mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
don't add empty blocks in ProposedNewObject
If the config contained a null block, don't convert it to a block with empty values for the proposed new value.
This commit is contained in:
parent
369d512e22
commit
e50be82da4
@ -25,6 +25,13 @@ import (
|
|||||||
// produce strange results with more "extreme" cases, such as a nested set
|
// produce strange results with more "extreme" cases, such as a nested set
|
||||||
// block where _all_ attributes are computed.
|
// block where _all_ attributes are computed.
|
||||||
func ProposedNewObject(schema *configschema.Block, prior, config cty.Value) cty.Value {
|
func ProposedNewObject(schema *configschema.Block, prior, config cty.Value) cty.Value {
|
||||||
|
// If the config and prior are both null, return early here before
|
||||||
|
// populating the prior block. The prevents non-null blocks from appearing
|
||||||
|
// the proposed state value.
|
||||||
|
if config.IsNull() && prior.IsNull() {
|
||||||
|
return prior
|
||||||
|
}
|
||||||
|
|
||||||
if prior.IsNull() {
|
if prior.IsNull() {
|
||||||
// In this case, we will construct a synthetic prior value that is
|
// In this case, we will construct a synthetic prior value that is
|
||||||
// similar to the result of decoding an empty configuration block,
|
// similar to the result of decoding an empty configuration block,
|
||||||
|
@ -83,6 +83,45 @@ func TestProposedNewObject(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
"null block remains null": {
|
||||||
|
&configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BlockTypes: map[string]*configschema.NestedBlock{
|
||||||
|
"baz": {
|
||||||
|
Nesting: configschema.NestingSingle,
|
||||||
|
Block: configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"boz": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"foo": cty.StringVal("bar"),
|
||||||
|
"baz": cty.NullVal(cty.Object(map[string]cty.Type{
|
||||||
|
"boz": cty.String,
|
||||||
|
})),
|
||||||
|
}),
|
||||||
|
// The baz block does not exist in the config, and therefore
|
||||||
|
// shouldn't be planned.
|
||||||
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"foo": cty.StringVal("bar"),
|
||||||
|
"baz": cty.NullVal(cty.Object(map[string]cty.Type{
|
||||||
|
"boz": cty.String,
|
||||||
|
})),
|
||||||
|
}),
|
||||||
|
},
|
||||||
"no prior with set": {
|
"no prior with set": {
|
||||||
// This one is here because our handling of sets is more complex
|
// This one is here because our handling of sets is more complex
|
||||||
// than others (due to the fuzzy correlation heuristic) and
|
// than others (due to the fuzzy correlation heuristic) and
|
||||||
|
Loading…
Reference in New Issue
Block a user