Skip to content

Commit f3c9238

Browse files
committed
Extract leading comments for resources and modules
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent 5f00545 commit f3c9238

26 files changed

+196
-55
lines changed

docs/reference/json.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,26 @@ generates the following output:
306306
{
307307
"name": "bar",
308308
"source": "baz",
309-
"version": "4.5.6"
309+
"version": "4.5.6",
310+
"description": null
310311
},
311312
{
312313
"name": "baz",
313314
"source": "baz",
314-
"version": "4.5.6"
315+
"version": "4.5.6",
316+
"description": null
315317
},
316318
{
317319
"name": "foo",
318320
"source": "bar",
319-
"version": "1.2.3"
321+
"version": "1.2.3",
322+
"description": "another type of description for module foo"
320323
},
321324
{
322325
"name": "foobar",
323326
"source": "git@github.com:module/path",
324-
"version": "v7.8.9"
327+
"version": "v7.8.9",
328+
"description": null
325329
}
326330
],
327331
"outputs": [
@@ -394,39 +398,44 @@ generates the following output:
394398
"provider": "foo",
395399
"source": "https://registry.acme.com/foo",
396400
"mode": "managed",
397-
"version": "latest"
401+
"version": "latest",
402+
"description": null
398403
},
399404
{
400405
"type": "resource",
401406
"name": "foo",
402407
"provider": "null",
403408
"source": "hashicorp/null",
404409
"mode": "managed",
405-
"version": "latest"
410+
"version": "latest",
411+
"description": null
406412
},
407413
{
408414
"type": "private_key",
409415
"name": "baz",
410416
"provider": "tls",
411417
"source": "hashicorp/tls",
412418
"mode": "managed",
413-
"version": "latest"
419+
"version": "latest",
420+
"description": "this description for tls_private_key.baz which can be multiline."
414421
},
415422
{
416423
"type": "caller_identity",
417424
"name": "current",
418425
"provider": "aws",
419426
"source": "hashicorp/aws",
420427
"mode": "data",
421-
"version": "latest"
428+
"version": "latest",
429+
"description": null
422430
},
423431
{
424432
"type": "caller_identity",
425433
"name": "ident",
426434
"provider": "aws",
427435
"source": "hashicorp/aws",
428436
"mode": "data",
429-
"version": "latest"
437+
"version": "latest",
438+
"description": null
430439
}
431440
]
432441
}

docs/reference/toml.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,25 @@ generates the following output:
290290
name = "bar"
291291
source = "baz"
292292
version = "4.5.6"
293+
description = ""
293294

294295
[[modules]]
295296
name = "baz"
296297
source = "baz"
297298
version = "4.5.6"
299+
description = ""
298300

299301
[[modules]]
300302
name = "foo"
301303
source = "bar"
302304
version = "1.2.3"
305+
description = "another type of description for module foo"
303306

304307
[[modules]]
305308
name = "foobar"
306309
source = "git@github.com:module/path"
307310
version = "v7.8.9"
311+
description = ""
308312

309313
[[outputs]]
310314
name = "output-0.12"
@@ -370,6 +374,7 @@ generates the following output:
370374
source = "https://registry.acme.com/foo"
371375
mode = "managed"
372376
version = "latest"
377+
description = ""
373378

374379
[[resources]]
375380
type = "resource"
@@ -378,6 +383,7 @@ generates the following output:
378383
source = "hashicorp/null"
379384
mode = "managed"
380385
version = "latest"
386+
description = ""
381387

382388
[[resources]]
383389
type = "private_key"
@@ -386,6 +392,7 @@ generates the following output:
386392
source = "hashicorp/tls"
387393
mode = "managed"
388394
version = "latest"
395+
description = "this description for tls_private_key.baz which can be multiline."
389396

390397
[[resources]]
391398
type = "caller_identity"
@@ -394,6 +401,7 @@ generates the following output:
394401
source = "hashicorp/aws"
395402
mode = "data"
396403
version = "latest"
404+
description = ""
397405

398406
[[resources]]
399407
type = "caller_identity"
@@ -402,5 +410,6 @@ generates the following output:
402410
source = "hashicorp/aws"
403411
mode = "data"
404412
version = "latest"
413+
description = ""
405414

406415
[examples]: https://github.com/terraform-docs/terraform-docs/tree/master/examples

docs/reference/xml.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,25 @@ generates the following output:
306306
<name>bar</name>
307307
<source>baz</source>
308308
<version>4.5.6</version>
309+
<description xsi:nil="true"></description>
309310
</module>
310311
<module>
311312
<name>baz</name>
312313
<source>baz</source>
313314
<version>4.5.6</version>
315+
<description xsi:nil="true"></description>
314316
</module>
315317
<module>
316318
<name>foo</name>
317319
<source>bar</source>
318320
<version>1.2.3</version>
321+
<description>another type of description for module foo</description>
319322
</module>
320323
<module>
321324
<name>foobar</name>
322325
<source>git@github.com:module/path</source>
323326
<version>v7.8.9</version>
327+
<description xsi:nil="true"></description>
324328
</module>
325329
</modules>
326330
<outputs>
@@ -394,6 +398,7 @@ generates the following output:
394398
<source>https://registry.acme.com/foo</source>
395399
<mode>managed</mode>
396400
<version>latest</version>
401+
<description xsi:nil="true"></description>
397402
</resource>
398403
<resource>
399404
<type>resource</type>
@@ -402,6 +407,7 @@ generates the following output:
402407
<source>hashicorp/null</source>
403408
<mode>managed</mode>
404409
<version>latest</version>
410+
<description xsi:nil="true"></description>
405411
</resource>
406412
<resource>
407413
<type>private_key</type>
@@ -410,6 +416,7 @@ generates the following output:
410416
<source>hashicorp/tls</source>
411417
<mode>managed</mode>
412418
<version>latest</version>
419+
<description>this description for tls_private_key.baz which can be multiline.</description>
413420
</resource>
414421
<resource>
415422
<type>caller_identity</type>
@@ -418,6 +425,7 @@ generates the following output:
418425
<source>hashicorp/aws</source>
419426
<mode>data</mode>
420427
<version>latest</version>
428+
<description xsi:nil="true"></description>
421429
</resource>
422430
<resource>
423431
<type>caller_identity</type>
@@ -426,6 +434,7 @@ generates the following output:
426434
<source>hashicorp/aws</source>
427435
<mode>data</mode>
428436
<version>latest</version>
437+
<description xsi:nil="true"></description>
429438
</resource>
430439
</resources>
431440
</module>

docs/reference/yaml.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,19 @@ generates the following output:
284284
- name: bar
285285
source: baz
286286
version: 4.5.6
287+
description: null
287288
- name: baz
288289
source: baz
289290
version: 4.5.6
291+
description: null
290292
- name: foo
291293
source: bar
292294
version: 1.2.3
295+
description: another type of description for module foo
293296
- name: foobar
294297
source: git@github.com:module/path
295298
version: v7.8.9
299+
description: null
296300
outputs:
297301
- name: output-0.12
298302
description: terraform 0.12 only
@@ -334,29 +338,34 @@ generates the following output:
334338
source: https://registry.acme.com/foo
335339
mode: managed
336340
version: latest
341+
description: null
337342
- type: resource
338343
name: foo
339344
provider: "null"
340345
source: hashicorp/null
341346
mode: managed
342347
version: latest
348+
description: null
343349
- type: private_key
344350
name: baz
345351
provider: tls
346352
source: hashicorp/tls
347353
mode: managed
348354
version: latest
355+
description: this description for tls_private_key.baz which can be multiline.
349356
- type: caller_identity
350357
name: current
351358
provider: aws
352359
source: hashicorp/aws
353360
mode: data
354361
version: latest
362+
description: null
355363
- type: caller_identity
356364
name: ident
357365
provider: aws
358366
source: hashicorp/aws
359367
mode: data
360368
version: latest
369+
description: null
361370

362371
[examples]: https://github.com/terraform-docs/terraform-docs/tree/master/examples

examples/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ terraform {
5050
}
5151
}
5252

53+
// this description for tls_private_key.baz
54+
// which can be multiline.
5355
resource "tls_private_key" "baz" {}
5456
resource "foo_resource" "baz" {}
5557

@@ -68,6 +70,7 @@ module "bar" {
6870
version = "4.5.6"
6971
}
7072

73+
# another type of description for module foo
7174
module "foo" {
7275
source = "bar"
7376
version = "1.2.3"

format/testdata/json/json-Base.golden

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,26 @@
249249
{
250250
"name": "bar",
251251
"source": "baz",
252-
"version": "4.5.6"
252+
"version": "4.5.6",
253+
"description": null
253254
},
254255
{
255256
"name": "foo",
256257
"source": "bar",
257-
"version": "1.2.3"
258+
"version": "1.2.3",
259+
"description": "another type of description for module foo"
258260
},
259261
{
260262
"name": "baz",
261263
"source": "baz",
262-
"version": "4.5.6"
264+
"version": "4.5.6",
265+
"description": null
263266
},
264267
{
265268
"name": "foobar",
266269
"source": "git@github.com:module/path",
267-
"version": "v7.8.9"
270+
"version": "v7.8.9",
271+
"description": null
268272
}
269273
],
270274
"outputs": [
@@ -337,39 +341,44 @@
337341
"provider": "foo",
338342
"source": "https://registry.acme.com/foo",
339343
"mode": "managed",
340-
"version": "latest"
344+
"version": "latest",
345+
"description": null
341346
},
342347
{
343348
"type": "resource",
344349
"name": "foo",
345350
"provider": "null",
346351
"source": "hashicorp/null",
347352
"mode": "managed",
348-
"version": "latest"
353+
"version": "latest",
354+
"description": null
349355
},
350356
{
351357
"type": "private_key",
352358
"name": "baz",
353359
"provider": "tls",
354360
"source": "hashicorp/tls",
355361
"mode": "managed",
356-
"version": "latest"
362+
"version": "latest",
363+
"description": "this description for tls_private_key.baz which can be multiline."
357364
},
358365
{
359366
"type": "caller_identity",
360367
"name": "current",
361368
"provider": "aws",
362369
"source": "hashicorp/aws",
363370
"mode": "data",
364-
"version": "latest"
371+
"version": "latest",
372+
"description": null
365373
},
366374
{
367375
"type": "caller_identity",
368376
"name": "ident",
369377
"provider": "aws",
370378
"source": "hashicorp/aws",
371379
"mode": "data",
372-
"version": "latest"
380+
"version": "latest",
381+
"description": null
373382
}
374383
]
375384
}

0 commit comments

Comments
 (0)