Skip to content

Commit 577cdbd

Browse files
committed
Migrate tags rule from TFLint core
1 parent b4fabaf commit 577cdbd

File tree

12 files changed

+1024
-5
lines changed

12 files changed

+1024
-5
lines changed

aws/runner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package aws
22

33
import (
4-
"fmt"
54
"log"
65

76
"github.com/hashicorp/hcl/v2"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# aws_resource_missing_tags
2+
3+
Require specific tags for all AWS resource types that support them.
4+
5+
## Configuration
6+
7+
```hcl
8+
rule "aws_resource_missing_tags" {
9+
enabled = true
10+
tags = ["Foo", "Bar"]
11+
exclude = ["aws_autoscaling_group"] # (Optional) Exclude some resource types from tag checks
12+
}
13+
```
14+
15+
## Examples
16+
17+
Most resources use the `tags` attribute with simple `key`=`value` pairs:
18+
19+
```hcl
20+
resource "aws_instance" "instance" {
21+
instance_type = "m5.large"
22+
tags = {
23+
foo = "Bar"
24+
bar = "Baz"
25+
}
26+
}
27+
```
28+
29+
```
30+
$ tflint
31+
1 issue(s) found:
32+
33+
Notice: aws_instance.instance is missing the following tags: "Bar", "Foo". (aws_resource_missing_tags)
34+
35+
on test.tf line 3:
36+
3: tags = {
37+
4: foo = "Bar"
38+
5: bar = "Baz"
39+
6: }
40+
```
41+
42+
Iterators in `dynamic` blocks cannot be expanded, so the tags in the following example will not be detected.
43+
44+
```hcl
45+
locals {
46+
tags = [
47+
{
48+
key = "Name",
49+
value = "SomeName",
50+
},
51+
{
52+
key = "env",
53+
value = "SomeEnv",
54+
},
55+
]
56+
}
57+
resource "aws_autoscaling_group" "this" {
58+
dynamic "tag" {
59+
for_each = local.tags
60+
61+
content {
62+
key = tag.key
63+
value = tag.value
64+
propagate_at_launch = true
65+
}
66+
}
67+
}
68+
```
69+
70+
## Why
71+
72+
You want to set a standardized set of tags for your AWS resources.
73+
74+
## How To Fix
75+
76+
For each resource type that supports tags, ensure that each missing tag is present.

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/onsi/ginkgo v1.14.2 // indirect
1414
github.com/onsi/gomega v1.10.3 // indirect
1515
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e
16-
github.com/terraform-linters/tflint-plugin-sdk v0.6.1-0.20201205142940-d49361e1c42c
16+
github.com/terraform-linters/tflint-plugin-sdk v0.6.1-0.20201213084811-8e12f90bd795
1717
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20201118192700-9cc6324740c9
18+
github.com/zclconf/go-cty v1.7.0
1819
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
326326
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
327327
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
328328
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
329-
github.com/terraform-linters/tflint-plugin-sdk v0.6.1-0.20201205142940-d49361e1c42c h1:c19JJeT1VbTXFpqaxi7FBAv4OJAeKVg0mpNs2ySbgi0=
330-
github.com/terraform-linters/tflint-plugin-sdk v0.6.1-0.20201205142940-d49361e1c42c/go.mod h1:EMiQwq0IiBwylbSgx53sdPBRhOHEXrjXhrD0x5C8SjY=
329+
github.com/terraform-linters/tflint-plugin-sdk v0.6.1-0.20201213084811-8e12f90bd795 h1:kPW/zt70sHHrRAnJ5PoxdTWSzx5e5NyabJElSfJ7Dmw=
330+
github.com/terraform-linters/tflint-plugin-sdk v0.6.1-0.20201213084811-8e12f90bd795/go.mod h1:EMiQwq0IiBwylbSgx53sdPBRhOHEXrjXhrD0x5C8SjY=
331331
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20201118192700-9cc6324740c9 h1:0u9SqTq2nbof0t+7xqfI8Ejhmooe3Qqe09fobOCZY6g=
332332
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20201118192700-9cc6324740c9/go.mod h1:sToOUnPCXFPwMljH57zM6uOI3q1YVREy4GSlg1Wm8/Y=
333333
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/terraform-linters/tflint-plugin-sdk/plugin"
55
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
66
"github.com/terraform-linters/tflint-ruleset-aws/aws"
7+
"github.com/terraform-linters/tflint-ruleset-aws/project"
78
"github.com/terraform-linters/tflint-ruleset-aws/rules"
89
"github.com/terraform-linters/tflint-ruleset-aws/rules/api"
910
)
@@ -13,7 +14,7 @@ func main() {
1314
RuleSet: &aws.RuleSet{
1415
BuiltinRuleSet: tflint.BuiltinRuleSet{
1516
Name: "aws",
16-
Version: "0.1.0",
17+
Version: project.Version,
1718
Rules: rules.Rules,
1819
},
1920
APIRules: api.Rules,

project/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package project
2+
3+
import "fmt"
4+
5+
// Version is ruleset version
6+
const Version string = "0.1.0"
7+
8+
// ReferenceLink returns the rule reference link
9+
func ReferenceLink(name string) string {
10+
return fmt.Sprintf("https://github.com/terraform-linters/tflint-ruleset-aws/blob/v%s/docs/rules/%s.md", Version, name)
11+
}

0 commit comments

Comments
 (0)