builtin/providers/terraform: terraform_data "id" is guaranteed non-null

The "id" attribute of this resource type is generated by the provider
itself and can never be null, so we'll refine the range of its unknown
result in case that helps downstream expressions to produce known results
even when the exact value hasn't yet been planned.
This commit is contained in:
Martin Atkins 2023-02-07 16:36:13 -08:00
parent 696cd68913
commit 691018dd00
2 changed files with 7 additions and 7 deletions

View File

@ -75,7 +75,7 @@ func planDataStoreResourceChange(req providers.PlanResourceChangeRequest) (resp
case req.PriorState.IsNull():
// Create
// Set the id value to unknown.
planned["id"] = cty.UnknownVal(cty.String)
planned["id"] = cty.UnknownVal(cty.String).RefineNotNull()
// Output type must always match the input, even when it's null.
if input.IsNull() {
@ -90,7 +90,7 @@ func planDataStoreResourceChange(req providers.PlanResourceChangeRequest) (resp
case !req.PriorState.GetAttr("triggers_replace").RawEquals(trigger):
// trigger changed, so we need to replace the entire instance
resp.RequiresReplace = append(resp.RequiresReplace, cty.GetAttrPath("triggers_replace"))
planned["id"] = cty.UnknownVal(cty.String)
planned["id"] = cty.UnknownVal(cty.String).RefineNotNull()
// We need to check the input for the replacement instance to compute a
// new output.

View File

@ -124,7 +124,7 @@ func TestManagedDataPlan(t *testing.T) {
"input": cty.NullVal(cty.DynamicPseudoType),
"output": cty.NullVal(cty.DynamicPseudoType),
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
"id": cty.UnknownVal(cty.String),
"id": cty.UnknownVal(cty.String).RefineNotNull(),
}),
},
@ -140,7 +140,7 @@ func TestManagedDataPlan(t *testing.T) {
"input": cty.NullVal(cty.String),
"output": cty.NullVal(cty.String),
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
"id": cty.UnknownVal(cty.String),
"id": cty.UnknownVal(cty.String).RefineNotNull(),
}),
},
@ -156,7 +156,7 @@ func TestManagedDataPlan(t *testing.T) {
"input": cty.StringVal("input"),
"output": cty.UnknownVal(cty.String),
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
"id": cty.UnknownVal(cty.String),
"id": cty.UnknownVal(cty.String).RefineNotNull(),
}),
},
@ -198,7 +198,7 @@ func TestManagedDataPlan(t *testing.T) {
"input": cty.StringVal("input"),
"output": cty.UnknownVal(cty.String),
"triggers_replace": cty.StringVal("new-value"),
"id": cty.UnknownVal(cty.String),
"id": cty.UnknownVal(cty.String).RefineNotNull(),
}),
},
@ -225,7 +225,7 @@ func TestManagedDataPlan(t *testing.T) {
"triggers_replace": cty.MapVal(map[string]cty.Value{
"key": cty.StringVal("new value"),
}),
"id": cty.UnknownVal(cty.String),
"id": cty.UnknownVal(cty.String).RefineNotNull(),
}),
},
} {