Skip to content

Commit 9c1cf65

Browse files
authored
fix(misconf): fix rendering of nested values in terraform plan lists (#10746)
1 parent f099dc4 commit 9c1cf65

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

pkg/iac/scanners/terraformplan/tfjson/parser/block.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,13 @@ func (r *hclRenderer) renderSlice(vals []any) {
144144
r.incIndent()
145145
defer r.decIndent()
146146

147-
for _, v := range vals {
147+
for i, v := range vals {
148148
r.write(r.indent + " ")
149-
renderPrimitive(r.w, v)
150-
r.writeln(",")
149+
r.renderAttributeValue(v)
150+
if i != len(vals)-1 {
151+
r.write(",")
152+
}
153+
r.writeln("")
151154
}
152155
r.write(r.indent + "]")
153156
}

pkg/iac/scanners/terraformplan/tfjson/parser/block_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,38 @@ func Test_ToHcl(t *testing.T) {
120120
to_port = 80
121121
}
122122
}
123+
`,
124+
},
125+
{
126+
name: "list attribute with nested lists",
127+
block: PlanBlock{
128+
BlockType: "resource",
129+
Type: "foo",
130+
Name: "bar",
131+
Attributes: map[string]any{
132+
"nested": []any{
133+
[]any{"a", "b"},
134+
[]any{"c"},
135+
[]any{"d", "e", "f"},
136+
},
137+
},
138+
},
139+
expected: `resource "foo" "bar" {
140+
nested = [
141+
[
142+
"a",
143+
"b"
144+
],
145+
[
146+
"c"
147+
],
148+
[
149+
"d",
150+
"e",
151+
"f"
152+
]
153+
]
154+
}
123155
`,
124156
},
125157
{

pkg/iac/scanners/terraformplan/tfjson/parser/parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resource "aws_security_group" "sg" {
5757
}
5858
ingress {
5959
cidr_blocks = [
60-
"0.0.0.0/0",
60+
"0.0.0.0/0"
6161
]
6262
description = ""
6363
from_port = 80

0 commit comments

Comments
 (0)