diff --git a/terraform/context_test.go b/terraform/context_test.go index ba4dfdab60..390fad2e10 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/hashicorp/hil" "github.com/hashicorp/terraform/config/configschema" "github.com/hashicorp/terraform/configs" "github.com/zclconf/go-cty/cty" @@ -234,6 +235,26 @@ func testDiffFn( } if k == "compute" { + if v == hil.UnknownValue { + // compute wasn't set in the config, so don't use these + // computed values from the schema. + delete(c.Raw, k) + delete(c.Raw, "compute_value") + + // we need to remove this from the list of ComputedKeys too, + // since it would get re-added to the diff further down + newComputed := make([]string, 0, len(c.ComputedKeys)) + for _, ck := range c.ComputedKeys { + if ck == "compute" || ck == "compute_value" { + continue + } + newComputed = append(newComputed, ck) + } + c.ComputedKeys = newComputed + + continue + } + attrDiff := &ResourceAttrDiff{ Old: "", New: "", @@ -248,7 +269,6 @@ func testDiffFn( } diff.Attributes[v.(string)] = attrDiff - continue } // If this key is not computed, then look it up in the @@ -579,6 +599,10 @@ func testProviderSchema(name string) *ProviderSchema { Type: cty.String, Optional: true, }, + "__template_requires_new": { + Type: cty.String, + Optional: true, + }, }, }, }, diff --git a/terraform/resource.go b/terraform/resource.go index 0aeaa58dc8..a5def42150 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -242,10 +242,6 @@ func NewResourceConfigShimmed(val cty.Value, schema *configschema.Block) *Resour } ret := &ResourceConfig{} - // Computed fields will all be present with unknown values. Strip them out - // before passing to the provider. - val = cty.UnknownAsNull(val) - legacyVal := hcl2shim.ConfigValueFromHCL2(val) ret.Config = legacyVal.(map[string]interface{}) // guaranteed compatible because we require an object type ret.Raw = ret.Config