core: don't panic if NewResourceConfigShimmed gets a null

When we're working on a create or destroy change it's expected for one of
the values to be null. Here we mimick the pre-0.12 behavior of producing
just an empty map in that case, which the helper/schema code (now the only
caller of this shim) then ignores completely.
pull/18800/head
Martin Atkins 8 years ago
parent a9019f994f
commit cb303a6d97

@ -8,15 +8,14 @@ import (
"strconv"
"strings"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/config/hcl2shim"
"github.com/hashicorp/terraform/config"
"github.com/mitchellh/copystructure"
"github.com/mitchellh/reflectwalk"
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/hcl2shim"
"github.com/hashicorp/terraform/configs/configschema"
)
// ResourceProvisionerConfig is used to pair a provisioner
@ -247,16 +246,20 @@ func NewResourceConfigShimmed(val cty.Value, schema *configschema.Block) *Resour
ret := &ResourceConfig{}
legacyVal := hcl2shim.ConfigValueFromHCL2(val)
ret.Config = legacyVal.(map[string]interface{}) // guaranteed compatible because we require an object type
if legacyVal != nil {
ret.Config = legacyVal.(map[string]interface{}) // guaranteed compatible because we require an object type
// Now we need to walk through our structure and find any unknown values,
// producing the separate list ComputedKeys to represent these. We use the
// schema here so that we can preserve the expected invariant
// that an attribute is always either wholly known or wholly unknown, while
// a child block can be partially unknown.
ret.ComputedKeys = newResourceConfigShimmedComputedKeys(val, schema, "")
} else {
ret.Config = make(map[string]interface{})
}
ret.Raw = ret.Config
// Now we need to walk through our structure and find any unknown values,
// producing the separate list ComputedKeys to represent these. We use the
// schema here so that we can preserve the expected invariant
// that an attribute is always either wholly known or wholly unknown, while
// a child block can be partially unknown.
ret.ComputedKeys = newResourceConfigShimmedComputedKeys(val, schema, "")
return ret
}

Loading…
Cancel
Save