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" {
2877
2877
2878
2878
require .Len (t , modules , 1 )
2879
2879
}
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
391
391
results = []iacTypes.StringValue {iacTypes .StringUnresolvable (a .metadata )}
392
392
}
393
393
}()
394
- if value .IsNull () {
395
- return []iacTypes.StringValue {iacTypes .StringUnresolvable (a .metadata )}
396
- }
397
- if ! value .IsKnown () {
394
+ if value .IsNull () || ! value .IsKnown () {
398
395
return []iacTypes.StringValue {iacTypes .StringUnresolvable (a .metadata )}
399
396
}
397
+
400
398
if value .Type ().IsListType () || value .Type ().IsTupleType () || value .Type ().IsSetType () {
401
399
for _ , val := range value .AsValueSlice () {
402
400
results = append (results , a .valueToString (val ))
@@ -828,7 +826,9 @@ func safeOp[T any](a *Attribute, fn func(cty.Value) T) T {
828
826
return res
829
827
}
830
828
831
- return fn (val )
829
+ unmarked , _ := val .UnmarkDeep ()
830
+
831
+ return fn (unmarked )
832
832
}
833
833
834
834
// 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 {
142
142
}
143
143
144
144
func 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
146
151
}
You can’t perform that action at this time.
0 commit comments