Skip to content

Commit

Permalink
Add support for count/each value
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Oct 12, 2022
1 parent fce5684 commit 1033e0a
Show file tree
Hide file tree
Showing 25 changed files with 1,248 additions and 243 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d
github.com/sourcegraph/jsonrpc2 v0.1.0
github.com/spf13/afero v1.9.2
github.com/terraform-linters/tflint-plugin-sdk v0.13.1-0.20221007143453-76cc99146499
github.com/terraform-linters/tflint-plugin-sdk v0.13.1-0.20221012144225-49187bd7fbc8
github.com/terraform-linters/tflint-ruleset-terraform v0.1.1
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zclconf/go-cty v1.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/terraform-linters/tflint-plugin-sdk v0.13.1-0.20221007143453-76cc99146499 h1:4abfVUQM2L3teOoJE7asKqzkG/NLvX+F2xuWpqaTeG8=
github.com/terraform-linters/tflint-plugin-sdk v0.13.1-0.20221007143453-76cc99146499/go.mod h1:oYEwDLOQrn3mIUQwiyXPBOnTqO1DcvRPnl/zOqHNu8A=
github.com/terraform-linters/tflint-plugin-sdk v0.13.1-0.20221012144225-49187bd7fbc8 h1:4jYoECTWvBo62A9E3M7/EUBjUYt3VXZg2ehJ8t3+jI8=
github.com/terraform-linters/tflint-plugin-sdk v0.13.1-0.20221012144225-49187bd7fbc8/go.mod h1:oYEwDLOQrn3mIUQwiyXPBOnTqO1DcvRPnl/zOqHNu8A=
github.com/terraform-linters/tflint-ruleset-terraform v0.1.1 h1:dAi25kUMZ3+c1aiQZlP+ifxXnRv+WNpSVSMBroUxeOI=
github.com/terraform-linters/tflint-ruleset-terraform v0.1.1/go.mod h1:+iOphcKeOXXNPqjc3STxHvJ+4km5y8Zo+qqqPLgqFFw=
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
Expand Down
20 changes: 20 additions & 0 deletions integrationtest/inspection/conditional/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@
},
"callers": []
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is t2.micro",
"range": {
"filename": "template.tf",
"start": {
"line": 61,
"column": 19
},
"end": {
"line": 61,
"column": 29
}
},
"callers": []
},
{
"rule": {
"name": "aws_iam_policy_example",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"count","Source":"./module","Dir":"module"},{"Key":"for_each","Source":"./module","Dir":"module"}]}
7 changes: 7 additions & 0 deletions integrationtest/inspection/expand/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugin "testing" {
enabled = true
}

plugin "terraform" {
enabled = false
}
31 changes: 31 additions & 0 deletions integrationtest/inspection/expand/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
resource "aws_instance" "count" {
count = 2

instance_type = "t${count.index}.micro"
}

resource "aws_instance" "for_each" {
for_each = {
v1 = "micro"
v2 = "medium"
}

instance_type = "${each.key}.${each.value}"
}

module "count" {
source = "./module"
count = 2

instance_type = "t${count.index}.micro"
}

module "for_each" {
source = "./module"
for_each = {
v1 = "micro"
v2 = "medium"
}

instance_type = "${each.key}.${each.value}"
}
5 changes: 5 additions & 0 deletions integrationtest/inspection/expand/module/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "instance_type" {}

resource "aws_instance" "foo" {
instance_type = var.instance_type
}
257 changes: 257 additions & 0 deletions integrationtest/inspection/expand/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
{
"issues": [
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is t0.micro",
"range": {
"filename": "main.tf",
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 42
}
},
"callers": []
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is t1.micro",
"range": {
"filename": "main.tf",
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 42
}
},
"callers": []
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is v1.micro",
"range": {
"filename": "main.tf",
"start": {
"line": 13,
"column": 19
},
"end": {
"line": 13,
"column": 46
}
},
"callers": []
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is v2.medium",
"range": {
"filename": "main.tf",
"start": {
"line": 13,
"column": 19
},
"end": {
"line": 13,
"column": 46
}
},
"callers": []
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is t0.micro",
"range": {
"filename": "main.tf",
"start": {
"line": 20,
"column": 19
},
"end": {
"line": 20,
"column": 42
}
},
"callers": [
{
"filename": "main.tf",
"start": {
"line": 20,
"column": 19
},
"end": {
"line": 20,
"column": 42
}
},
{
"filename": "module/main.tf",
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 36
}
}
]
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is t1.micro",
"range": {
"filename": "main.tf",
"start": {
"line": 20,
"column": 19
},
"end": {
"line": 20,
"column": 42
}
},
"callers": [
{
"filename": "main.tf",
"start": {
"line": 20,
"column": 19
},
"end": {
"line": 20,
"column": 42
}
},
{
"filename": "module/main.tf",
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 36
}
}
]
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is v1.micro",
"range": {
"filename": "main.tf",
"start": {
"line": 30,
"column": 19
},
"end": {
"line": 30,
"column": 46
}
},
"callers": [
{
"filename": "main.tf",
"start": {
"line": 30,
"column": 19
},
"end": {
"line": 30,
"column": 46
}
},
{
"filename": "module/main.tf",
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 36
}
}
]
},
{
"rule": {
"name": "aws_instance_example_type",
"severity": "error",
"link": ""
},
"message": "instance type is v2.medium",
"range": {
"filename": "main.tf",
"start": {
"line": 30,
"column": 19
},
"end": {
"line": 30,
"column": 46
}
},
"callers": [
{
"filename": "main.tf",
"start": {
"line": 30,
"column": 19
},
"end": {
"line": 30,
"column": 46
}
},
{
"filename": "module/main.tf",
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 36
}
}
]
}
],
"errors": []
}
5 changes: 5 additions & 0 deletions integrationtest/inspection/inspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ func TestIntegration(t *testing.T) {
Command: "tflint --format json",
Dir: "incompatible-host",
},
{
Name: "expand resources/modules",
Command: "tflint --module --format json",
Dir: "expand",
},
}

// Disable the bundled plugin because the `os.Executable()` is go(1) in the tests
Expand Down
Loading

0 comments on commit 1033e0a

Please sign in to comment.