typed null input should be reflected in output

The configuration may be supplying a typed null value to the
terraform_data.input attribute, which must be reflected in the output to
have a valid plan.
This commit is contained in:
James Bardin 2023-01-13 10:49:25 -05:00
parent 95782f2491
commit e2a6397a06
2 changed files with 21 additions and 3 deletions

View File

@ -74,8 +74,10 @@ func planDataStoreResourceChange(req providers.PlanResourceChangeRequest) (resp
// Set the id value to unknown.
planned["id"] = cty.UnknownVal(cty.String)
// Only compute a new output if input has a non-null value.
if !input.IsNull() {
// Output type must always match the input, even when it's null.
if input.IsNull() {
planned["output"] = cty.NullVal(input.Type())
} else {
planned["output"] = cty.UnknownVal(input.Type())
}
@ -90,7 +92,7 @@ func planDataStoreResourceChange(req providers.PlanResourceChangeRequest) (resp
// We need to check the input for the replacement instance to compute a
// new output.
if input.IsNull() {
planned["output"] = cty.NullVal(cty.DynamicPseudoType)
planned["output"] = cty.NullVal(input.Type())
} else {
planned["output"] = cty.UnknownVal(input.Type())
}

View File

@ -125,6 +125,22 @@ func TestManagedDataPlan(t *testing.T) {
}),
},
"create-typed-null-input": {
prior: cty.NullVal(ty),
proposed: cty.ObjectVal(map[string]cty.Value{
"input": cty.NullVal(cty.String),
"output": cty.NullVal(cty.DynamicPseudoType),
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
"id": cty.NullVal(cty.String),
}),
planned: cty.ObjectVal(map[string]cty.Value{
"input": cty.NullVal(cty.String),
"output": cty.NullVal(cty.String),
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
"id": cty.UnknownVal(cty.String),
}),
},
"create-output": {
prior: cty.NullVal(ty),
proposed: cty.ObjectVal(map[string]cty.Value{