File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
scanners/terraform/parser Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ type ModuleDefinition struct {
2525}
2626
2727func (d * ModuleDefinition ) inputVars () map [string ]cty.Value {
28- inputs := d .Definition .Values ().AsValueMap ()
28+ inputs := d .Definition .NullableValues ().AsValueMap ()
2929 if inputs == nil {
3030 return make (map [string ]cty.Value )
3131 }
Original file line number Diff line number Diff line change @@ -2161,3 +2161,29 @@ resource "foo" "this" {
21612161 })
21622162 }
21632163}
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 {
569569 return attributes
570570}
571571
572+ func (b * Block ) NullableValues () cty.Value {
573+ return b .values (true )
574+ }
575+
572576func (b * Block ) Values () cty.Value {
577+ return b .values (false )
578+ }
579+
580+ func (b * Block ) values (allowNull bool ) cty.Value {
573581 values := createPresetValues (b )
574582 for _ , attribute := range b .GetAttributes () {
575583 if attribute .Name () == "for_each" {
576584 continue
577585 }
578- values [attribute .Name ()] = attribute .NullableValue ()
586+ if allowNull {
587+ values [attribute .Name ()] = attribute .NullableValue ()
588+ } else {
589+ values [attribute .Name ()] = attribute .Value ()
590+ }
579591 }
580592 return cty .ObjectVal (postProcessValues (b , values ))
581593}
You can’t perform that action at this time.
0 commit comments