File tree 3 files changed +40
-2
lines changed
scanners/terraform/parser
3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ type ModuleDefinition struct {
25
25
}
26
26
27
27
func (d * ModuleDefinition ) inputVars () map [string ]cty.Value {
28
- inputs := d .Definition .Values ().AsValueMap ()
28
+ inputs := d .Definition .NullableValues ().AsValueMap ()
29
29
if inputs == nil {
30
30
return make (map [string ]cty.Value )
31
31
}
Original file line number Diff line number Diff line change @@ -2161,3 +2161,29 @@ resource "foo" "this" {
2161
2161
})
2162
2162
}
2163
2163
}
2164
+
2165
+ func TestAttrRefToNullVariable (t * testing.T ) {
2166
+ fsys := fstest.MapFS {
2167
+ "main.tf" : & fstest.MapFile {Data : []byte (`variable "name" {
2168
+ type = string
2169
+ default = null
2170
+ }
2171
+
2172
+ resource "aws_s3_bucket" "example" {
2173
+ bucket = var.name
2174
+ }` )},
2175
+ }
2176
+
2177
+ parser := New (fsys , "" , OptionStopOnHCLError (true ))
2178
+
2179
+ require .NoError (t , parser .ParseFS (context .TODO (), "." ))
2180
+
2181
+ _ , err := parser .Load (context .TODO ())
2182
+ require .NoError (t , err )
2183
+
2184
+ modules , _ , err := parser .EvaluateAll (context .TODO ())
2185
+ require .NoError (t , err )
2186
+
2187
+ val := modules .GetResourcesByType ("aws_s3_bucket" )[0 ].GetAttribute ("bucket" ).GetRawValue ()
2188
+ assert .Nil (t , val )
2189
+ }
Original file line number Diff line number Diff line change @@ -569,13 +569,25 @@ func (b *Block) Attributes() map[string]*Attribute {
569
569
return attributes
570
570
}
571
571
572
+ func (b * Block ) NullableValues () cty.Value {
573
+ return b .values (true )
574
+ }
575
+
572
576
func (b * Block ) Values () cty.Value {
577
+ return b .values (false )
578
+ }
579
+
580
+ func (b * Block ) values (allowNull bool ) cty.Value {
573
581
values := createPresetValues (b )
574
582
for _ , attribute := range b .GetAttributes () {
575
583
if attribute .Name () == "for_each" {
576
584
continue
577
585
}
578
- values [attribute .Name ()] = attribute .NullableValue ()
586
+ if allowNull {
587
+ values [attribute .Name ()] = attribute .NullableValue ()
588
+ } else {
589
+ values [attribute .Name ()] = attribute .Value ()
590
+ }
579
591
}
580
592
return cty .ObjectVal (postProcessValues (b , values ))
581
593
}
You can’t perform that action at this time.
0 commit comments