File tree Expand file tree Collapse file tree 3 files changed +47
-6
lines changed
scanners/terraform/parser Expand file tree Collapse file tree 3 files changed +47
-6
lines changed Original file line number Diff line number Diff line change @@ -2877,3 +2877,39 @@ module "test" {
28772877
28782878 require .Len (t , modules , 1 )
28792879}
2880+
2881+ func Test_MarkedValues (t * testing.T ) {
2882+
2883+ tests := []struct {
2884+ name string
2885+ src string
2886+ }{
2887+ {
2888+ name : "marked object" ,
2889+ src : `resource "foo" "bar" {
2890+ test = sensitive({})
2891+ }` ,
2892+ },
2893+ }
2894+
2895+ for _ , tt := range tests {
2896+ t .Run (tt .name , func (t * testing.T ) {
2897+ files := map [string ]string {
2898+ `main.tf` : tt .src ,
2899+ }
2900+
2901+ fsys := testutil .CreateFS (t , files )
2902+ parser := New (fsys , "" ,
2903+ OptionWithSkipCachedModules (true ),
2904+ OptionStopOnHCLError (true ),
2905+ )
2906+ err := parser .ParseFS (t .Context (), "." )
2907+ require .NoError (t , err )
2908+
2909+ modules , err := parser .EvaluateAll (t .Context ())
2910+ require .NoError (t , err )
2911+
2912+ require .Len (t , modules , 1 )
2913+ })
2914+ }
2915+ }
Original file line number Diff line number Diff line change @@ -391,12 +391,10 @@ func (a *Attribute) valueToStrings(value cty.Value) (results []iacTypes.StringVa
391391 results = []iacTypes.StringValue {iacTypes .StringUnresolvable (a .metadata )}
392392 }
393393 }()
394- if value .IsNull () {
395- return []iacTypes.StringValue {iacTypes .StringUnresolvable (a .metadata )}
396- }
397- if ! value .IsKnown () {
394+ if value .IsNull () || ! value .IsKnown () {
398395 return []iacTypes.StringValue {iacTypes .StringUnresolvable (a .metadata )}
399396 }
397+
400398 if value .Type ().IsListType () || value .Type ().IsTupleType () || value .Type ().IsSetType () {
401399 for _ , val := range value .AsValueSlice () {
402400 results = append (results , a .valueToString (val ))
@@ -828,7 +826,9 @@ func safeOp[T any](a *Attribute, fn func(cty.Value) T) T {
828826 return res
829827 }
830828
831- return fn (val )
829+ unmarked , _ := val .UnmarkDeep ()
830+
831+ return fn (unmarked )
832832}
833833
834834// RewriteExpr applies the given function `transform` to the expression of the attribute,
Original file line number Diff line number Diff line change @@ -142,5 +142,10 @@ func mergeObjects(a, b cty.Value) cty.Value {
142142}
143143
144144func isNotEmptyObject (val cty.Value ) bool {
145- return ! val .IsNull () && val .IsKnown () && val .Type ().IsObjectType () && val .LengthInt () > 0
145+ if val .IsNull () || ! val .IsKnown () || ! val .Type ().IsObjectType () {
146+ return false
147+ }
148+
149+ unmarked , _ := val .Unmark ()
150+ return unmarked .LengthInt () > 0
146151}
You can’t perform that action at this time.
0 commit comments