File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ func (d *Defaults) apply(v cty.Value) cty.Value {
95
95
}
96
96
values [key ] = defaultValue
97
97
}
98
- if defaultRng := defaultValue .Range (); defaultRng .DefinitelyNotNull () {
98
+ if defaultRng := defaultValue .Range (); defaultRng .DefinitelyNotNull () && values [ key ]. Type () != cty . DynamicPseudoType {
99
99
values [key ] = values [key ].RefineNotNull ()
100
100
}
101
101
}
Original file line number Diff line number Diff line change @@ -898,6 +898,23 @@ func TestDefaults_Apply(t *testing.T) {
898
898
"foo" : cty .UnknownVal (cty .String ).RefineNotNull (),
899
899
}),
900
900
},
901
+ "optional attribute with dynamic value can be null" : {
902
+ defaults : & Defaults {
903
+ Type : cty .ObjectWithOptionalAttrs (map [string ]cty.Type {
904
+ "foo" : cty .String ,
905
+ }, []string {"foo" }),
906
+ DefaultValues : map [string ]cty.Value {
907
+ "foo" : cty .StringVal ("bar" ), // Important: default is non-null
908
+ },
909
+ },
910
+ value : cty .ObjectVal (map [string ]cty.Value {
911
+ "foo" : cty .DynamicVal ,
912
+ }),
913
+ want : cty .ObjectVal (map [string ]cty.Value {
914
+ // The default value is itself non-null, but dynamic value cannot be refined.
915
+ "foo" : cty .DynamicVal ,
916
+ }),
917
+ },
901
918
}
902
919
903
920
for name , tc := range testCases {
You can’t perform that action at this time.
0 commit comments