From d55d623ef0e3954f85a92aa596bf3e4903f1562d Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 22 May 2018 19:02:22 -0400 Subject: [PATCH] handle unset computed values in tests The old testDiffFn used th raw config to dynamically set computed values in the diff. Since the schema now defines what values should be there, all test diffs end up with unkown computed values. Filter these out by looking for a value set to "compute" --- terraform/context_test.go | 26 +++++++++++++++++++++++++- terraform/resource.go | 4 ---- 2 files changed, 25 insertions(+), 5 deletions(-) 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