Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/typeexpr: Avoid refinements on dynamic values #625

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/typeexpr/defaults.go
Expand Up @@ -95,7 +95,7 @@ func (d *Defaults) apply(v cty.Value) cty.Value {
}
values[key] = defaultValue
}
if defaultRng := defaultValue.Range(); defaultRng.DefinitelyNotNull() {
if defaultRng := defaultValue.Range(); defaultRng.DefinitelyNotNull() && values[key].Type() != cty.DynamicPseudoType {
values[key] = values[key].RefineNotNull()
}
}
Expand Down
17 changes: 17 additions & 0 deletions ext/typeexpr/defaults_test.go
Expand Up @@ -898,6 +898,23 @@ func TestDefaults_Apply(t *testing.T) {
"foo": cty.UnknownVal(cty.String).RefineNotNull(),
}),
},
"optional attribute with dynamic value can be null": {
defaults: &Defaults{
Type: cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"foo": cty.String,
}, []string{"foo"}),
DefaultValues: map[string]cty.Value{
"foo": cty.StringVal("bar"), // Important: default is non-null
},
},
value: cty.ObjectVal(map[string]cty.Value{
"foo": cty.DynamicVal,
}),
want: cty.ObjectVal(map[string]cty.Value{
// The default value is itself non-null, but dynamic value cannot be refined.
"foo": cty.DynamicVal,
}),
},
}

for name, tc := range testCases {
Expand Down