From 691018dd00a8b08255126ed823239ff8778aaa20 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 7 Feb 2023 16:36:13 -0800 Subject: [PATCH] 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. --- internal/builtin/providers/terraform/resource_data.go | 4 ++-- .../builtin/providers/terraform/resource_data_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/builtin/providers/terraform/resource_data.go b/internal/builtin/providers/terraform/resource_data.go index 6fdba7ea5c..a17c60fc0b 100644 --- a/internal/builtin/providers/terraform/resource_data.go +++ b/internal/builtin/providers/terraform/resource_data.go @@ -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. diff --git a/internal/builtin/providers/terraform/resource_data_test.go b/internal/builtin/providers/terraform/resource_data_test.go index 28a038333f..3adb4484d1 100644 --- a/internal/builtin/providers/terraform/resource_data_test.go +++ b/internal/builtin/providers/terraform/resource_data_test.go @@ -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(), }), }, } {