Skip to content

Commit 8f74fd4

Browse files
committed
feat: ignore outputs, providers, resources with comments
Prepend any type of resource, including `resource`, `data`, `module`, `variable`, and `output` with a comment including "terraform-docs-ignore" to exclude it from the generated output. Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent 943489c commit 8f74fd4

File tree

19 files changed

+261
-14
lines changed

19 files changed

+261
-14
lines changed

docs/how-to/generate-terraform-tfvars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "How to generate terraform.tfvars file with terraform-docs"
44
menu:
55
docs:
66
parent: "how-to"
7-
weight: 207
7+
weight: 208
88
toc: false
99
---
1010

docs/how-to/github-action.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "How to use terraform-docs with GitHub Actions"
44
menu:
55
docs:
66
parent: "how-to"
7-
weight: 208
7+
weight: 209
88
toc: false
99
---
1010

docs/how-to/ignore-resources.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: "Ignore Resources to be Generated"
3+
description: "How to ignore resources from generated output"
4+
menu:
5+
docs:
6+
parent: "how-to"
7+
weight: 204
8+
toc: false
9+
---
10+
11+
Since `v0.18.0`
12+
13+
Any type of resources can be ignored from the generated output by prepending them
14+
with a comment `terraform-docs-ignore`. Supported type of Terraform resources to
15+
get ignored are:
16+
17+
- `resource`
18+
- `data`
19+
- `module`
20+
- `variable`
21+
- `output`
22+
23+
{{< alert type="info" >}}
24+
If a `resource` or `data` is ignored, their corresponding discovered provider
25+
will also get ignored from "Providers" section.
26+
{{< /alert>}}
27+
28+
Take the following example:
29+
30+
```hcl
31+
##################################################################
32+
# All of the following will be ignored from the generated output #
33+
##################################################################
34+
35+
# terraform-docs-ignore
36+
resource "foo_resource" "foo" {}
37+
38+
# This resource is going to get ignored from generated
39+
# output by using the following known comment.
40+
#
41+
# terraform-docs-ignore
42+
#
43+
# The ignore keyword also doesn't have to be the first,
44+
# last, or the only thing in a leading comment
45+
resource "bar_resource" "bar" {}
46+
47+
# terraform-docs-ignore
48+
data "foo_data_resource" "foo" {}
49+
50+
# terraform-docs-ignore
51+
data "bar_data_resource" "bar" {}
52+
53+
// terraform-docs-ignore
54+
module "foo" {
55+
source = "foo"
56+
version = "x.x.x"
57+
}
58+
59+
# terraform-docs-ignore
60+
variable "foo" {
61+
default = "foo"
62+
}
63+
64+
// terraform-docs-ignore
65+
output "foo" {
66+
value = "foo"
67+
}
68+
```
69+
70+
{{< alert type="info" >}}
71+
The ignore keyword (i.e. `terraform-docs-ignore`) doesn't have to be the first,
72+
last, or only thing in a leading comment. As long as the keyword is present in
73+
a comment, the following resource will get ignored.
74+
{{< /alert>}}

docs/how-to/include-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "How to include example in terraform-docs generated output"
44
menu:
55
docs:
66
parent: "how-to"
7-
weight: 205
7+
weight: 206
88
toc: false
99
---
1010

docs/how-to/insert-output-to-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "How to insert generated terraform-docs output to file"
44
menu:
55
docs:
66
parent: "how-to"
7-
weight: 204
7+
weight: 205
88
toc: false
99
---
1010

docs/how-to/pre-commit-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "How to use pre-commit hooks with terraform-docs"
44
menu:
55
docs:
66
parent: "how-to"
7-
weight: 209
7+
weight: 210
88
toc: false
99
---
1010

docs/how-to/recursive-submodules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "How to generate submodules documentation recursively with terrafor
44
menu:
55
docs:
66
parent: "how-to"
7-
weight: 206
7+
weight: 207
88
toc: false
99
---
1010

examples/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,20 @@ data "aws_caller_identity" "ident" {
6363
provider = "aws.ident"
6464
}
6565

66+
# terraform-docs-ignore
67+
data "aws_caller_identity" "ignored" {
68+
provider = "aws"
69+
}
70+
6671
resource "null_resource" "foo" {}
6772

73+
# This resource is going to get ignored from generated
74+
# output by using the following known comment.
75+
# terraform-docs-ignore
76+
# And the ignore keyword also doesn't have to be the first,
77+
# last, or only thing in a leading comment
78+
resource "null_resource" "ignored" {}
79+
6880
module "bar" {
6981
source = "baz"
7082
version = "4.5.6"
@@ -84,3 +96,9 @@ module "baz" {
8496
module "foobar" {
8597
source = "git@github.com:module/path?ref=v7.8.9"
8698
}
99+
100+
// terraform-docs-ignore
101+
module "ignored" {
102+
source = "foobaz"
103+
version = "7.8.9"
104+
}

examples/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ output "output-0.12" {
1717
value = join(",", var.list-3)
1818
description = "terraform 0.12 only"
1919
}
20+
21+
// terraform-docs-ignore
22+
output "ignored" {
23+
value = "ignored"
24+
}

examples/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ variable "bool-1" {
1414
default = true
1515
}
1616

17+
# terraform-docs-ignore
18+
variable "ignored" {
19+
default = ""
20+
}
21+
1722
variable "string-3" {
1823
default = ""
1924
}

0 commit comments

Comments
 (0)