Skip to content

Commit

Permalink
Add support for dynamic blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Nov 12, 2022
1 parent db2fa60 commit b0072fd
Show file tree
Hide file tree
Showing 31 changed files with 1,634 additions and 998 deletions.
3 changes: 3 additions & 0 deletions integrationtest/inspection/dynblock-unknown/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugin "testing" {
enabled = true
}
69 changes: 69 additions & 0 deletions integrationtest/inspection/dynblock-unknown/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
variable "unknown_set" {
type = set(bool)
}

variable "unknown_bool" {
type = bool
}

resource "aws_s3_bucket" "main" {
lifecycle_rule {
enabled = true
}

dynamic "lifecycle_rule" {
for_each = var.unknown_set

content {
enabled = lifecycle_rule.value
}
}

dynamic "lifecycle_rule" {
for_each = toset([var.unknown_bool])

content {
enabled = lifecycle_rule.value
}
}
}

resource "aws_iam_role" "main" {
inline_policy {
name = "static"
}

dynamic "inline_policy" {
for_each = toset(["foo", "bar"])

content {
name = inline_policy.value
}
}

dynamic "inline_policy" {
for_each = var.unknown_set

content {
name = inline_policy.value
}
}
}

resource "testing_assertions" "main" {
equal "static" {}

dynamic "equal" {
for_each = toset(["known_label"])
iterator = it
labels = [it.value]
content {}
}

dynamic "equal" {
for_each = toset(["unknown_label"])
iterator = it
labels = ["${it.value}-${var.unknown_bool}"]
content {}
}
}
145 changes: 145 additions & 0 deletions integrationtest/inspection/dynblock-unknown/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"issues": [
{
"rule": {
"name": "aws_s3_bucket_example_lifecycle_rule",
"severity": "error",
"link": ""
},
"message": "`lifecycle_rule` block found",
"range": {
"filename": "main.tf",
"start": {
"line": 10,
"column": 3
},
"end": {
"line": 10,
"column": 17
}
},
"callers": []
},
{
"rule": {
"name": "aws_s3_bucket_example_lifecycle_rule",
"severity": "error",
"link": ""
},
"message": "`enabled` attribute found: true",
"range": {
"filename": "main.tf",
"start": {
"line": 11,
"column": 15
},
"end": {
"line": 11,
"column": 19
}
},
"callers": []
},
{
"rule": {
"name": "aws_s3_bucket_example_lifecycle_rule",
"severity": "error",
"link": ""
},
"message": "`lifecycle_rule` block found",
"range": {
"filename": "main.tf",
"start": {
"line": 22,
"column": 3
},
"end": {
"line": 22,
"column": 27
}
},
"callers": []
},
{
"rule": {
"name": "aws_iam_role_example",
"severity": "error",
"link": ""
},
"message": "inline policy found",
"range": {
"filename": "main.tf",
"start": {
"line": 32,
"column": 3
},
"end": {
"line": 32,
"column": 16
}
},
"callers": []
},
{
"rule": {
"name": "aws_iam_role_example",
"severity": "error",
"link": ""
},
"message": "name is static",
"range": {
"filename": "main.tf",
"start": {
"line": 33,
"column": 12
},
"end": {
"line": 33,
"column": 20
}
},
"callers": []
},
{
"rule": {
"name": "testing_assertions_example",
"severity": "error",
"link": ""
},
"message": "equal block found: label=static",
"range": {
"filename": "main.tf",
"start": {
"line": 54,
"column": 3
},
"end": {
"line": 54,
"column": 17
}
},
"callers": []
},
{
"rule": {
"name": "testing_assertions_example",
"severity": "error",
"link": ""
},
"message": "equal block found: label=known_label",
"range": {
"filename": "main.tf",
"start": {
"line": 56,
"column": 3
},
"end": {
"line": 56,
"column": 18
}
},
"callers": []
}
],
"errors": []
}
Loading

0 comments on commit b0072fd

Please sign in to comment.