mirror of https://github.com/hashicorp/terraform
Merge #20265: Don't presume unknown for values unset in config
This changes the contract for `PlanResourceChange` so that the provider is now responsible for populating all default values during plan, including inserting any unknown values for defaults it will fill in at apply time.pull/20292/head
commit
6eb7bfbdfb
@ -0,0 +1,131 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
// SetUnknowns takes a cty.Value, and compares it to the schema setting any null
|
||||
// values which are computed to unknown.
|
||||
func SetUnknowns(val cty.Value, schema *configschema.Block) cty.Value {
|
||||
if !val.IsKnown() {
|
||||
return val
|
||||
}
|
||||
|
||||
// If the object was null, we still need to handle the top level attributes
|
||||
// which might be computed, but we don't need to expand the blocks.
|
||||
if val.IsNull() {
|
||||
objMap := map[string]cty.Value{}
|
||||
allNull := true
|
||||
for name, attr := range schema.Attributes {
|
||||
switch {
|
||||
case attr.Computed:
|
||||
objMap[name] = cty.UnknownVal(attr.Type)
|
||||
allNull = false
|
||||
default:
|
||||
objMap[name] = cty.NullVal(attr.Type)
|
||||
}
|
||||
}
|
||||
|
||||
// If this object has no unknown attributes, then we can leave it null.
|
||||
if allNull {
|
||||
return val
|
||||
}
|
||||
|
||||
return cty.ObjectVal(objMap)
|
||||
}
|
||||
|
||||
valMap := val.AsValueMap()
|
||||
newVals := make(map[string]cty.Value)
|
||||
|
||||
for name, attr := range schema.Attributes {
|
||||
v := valMap[name]
|
||||
|
||||
if attr.Computed && v.IsNull() {
|
||||
newVals[name] = cty.UnknownVal(attr.Type)
|
||||
continue
|
||||
}
|
||||
|
||||
newVals[name] = v
|
||||
}
|
||||
|
||||
for name, blockS := range schema.BlockTypes {
|
||||
blockVal := valMap[name]
|
||||
if blockVal.IsNull() || !blockVal.IsKnown() {
|
||||
newVals[name] = blockVal
|
||||
continue
|
||||
}
|
||||
|
||||
blockValType := blockVal.Type()
|
||||
blockElementType := blockS.Block.ImpliedType()
|
||||
|
||||
// This switches on the value type here, so we can correctly switch
|
||||
// between Tuples/Lists and Maps/Objects.
|
||||
switch {
|
||||
case blockS.Nesting == configschema.NestingSingle:
|
||||
// NestingSingle is the only exception here, where we treat the
|
||||
// block directly as an object
|
||||
newVals[name] = SetUnknowns(blockVal, &blockS.Block)
|
||||
|
||||
case blockValType.IsSetType(), blockValType.IsListType(), blockValType.IsTupleType():
|
||||
listVals := blockVal.AsValueSlice()
|
||||
newListVals := make([]cty.Value, 0, len(listVals))
|
||||
|
||||
for _, v := range listVals {
|
||||
newListVals = append(newListVals, SetUnknowns(v, &blockS.Block))
|
||||
}
|
||||
|
||||
switch {
|
||||
case blockValType.IsSetType():
|
||||
switch len(newListVals) {
|
||||
case 0:
|
||||
newVals[name] = cty.SetValEmpty(blockElementType)
|
||||
default:
|
||||
newVals[name] = cty.SetVal(newListVals)
|
||||
}
|
||||
case blockValType.IsListType():
|
||||
switch len(newListVals) {
|
||||
case 0:
|
||||
newVals[name] = cty.ListValEmpty(blockElementType)
|
||||
default:
|
||||
newVals[name] = cty.ListVal(newListVals)
|
||||
}
|
||||
case blockValType.IsTupleType():
|
||||
newVals[name] = cty.TupleVal(newListVals)
|
||||
}
|
||||
|
||||
case blockValType.IsMapType(), blockValType.IsObjectType():
|
||||
mapVals := blockVal.AsValueMap()
|
||||
newMapVals := make(map[string]cty.Value)
|
||||
|
||||
for k, v := range mapVals {
|
||||
newMapVals[k] = SetUnknowns(v, &blockS.Block)
|
||||
}
|
||||
|
||||
switch {
|
||||
case blockValType.IsMapType():
|
||||
switch len(newMapVals) {
|
||||
case 0:
|
||||
newVals[name] = cty.MapValEmpty(blockElementType)
|
||||
default:
|
||||
newVals[name] = cty.MapVal(newMapVals)
|
||||
}
|
||||
case blockValType.IsObjectType():
|
||||
if len(newMapVals) == 0 {
|
||||
// We need to populate empty values to make a valid object.
|
||||
for attr, ty := range blockElementType.AttributeTypes() {
|
||||
newMapVals[attr] = cty.NullVal(ty)
|
||||
}
|
||||
}
|
||||
newVals[name] = cty.ObjectVal(newMapVals)
|
||||
}
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("failed to set unknown values for nested block %q:%#v", name, blockValType))
|
||||
}
|
||||
}
|
||||
|
||||
return cty.ObjectVal(newVals)
|
||||
}
|
||||
@ -0,0 +1,483 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
func TestSetUnknowns(t *testing.T) {
|
||||
for n, tc := range map[string]struct {
|
||||
Schema *configschema.Block
|
||||
Val cty.Value
|
||||
Expected cty.Value
|
||||
}{
|
||||
"empty": {
|
||||
&configschema.Block{},
|
||||
cty.EmptyObjectVal,
|
||||
cty.EmptyObjectVal,
|
||||
},
|
||||
"no prior": {
|
||||
&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"baz": {
|
||||
Nesting: configschema.NestingSingle,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"boz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"biz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.NullVal(cty.Object(map[string]cty.Type{
|
||||
"foo": cty.String,
|
||||
"bar": cty.String,
|
||||
"baz": cty.Object(map[string]cty.Type{
|
||||
"boz": cty.String,
|
||||
"biz": cty.String,
|
||||
}),
|
||||
})),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.NullVal(cty.String),
|
||||
"bar": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
},
|
||||
"null stays null": {
|
||||
// if the object has no computed attributes, it should stay null
|
||||
&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": &configschema.Attribute{
|
||||
Type: cty.String,
|
||||
},
|
||||
},
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"baz": {
|
||||
Nesting: configschema.NestingSet,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"boz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.NullVal(cty.Object(map[string]cty.Type{
|
||||
"foo": cty.String,
|
||||
"baz": cty.Set(cty.Object(map[string]cty.Type{
|
||||
"boz": cty.String,
|
||||
})),
|
||||
})),
|
||||
cty.NullVal(cty.Object(map[string]cty.Type{
|
||||
"foo": cty.String,
|
||||
"baz": cty.Set(cty.Object(map[string]cty.Type{
|
||||
"boz": cty.String,
|
||||
})),
|
||||
})),
|
||||
},
|
||||
"no prior with set": {
|
||||
// the set value should remain null
|
||||
&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": &configschema.Attribute{
|
||||
Type: cty.String,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"baz": {
|
||||
Nesting: configschema.NestingSet,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"boz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.NullVal(cty.Object(map[string]cty.Type{
|
||||
"foo": cty.String,
|
||||
"baz": cty.Set(cty.Object(map[string]cty.Type{
|
||||
"boz": cty.String,
|
||||
})),
|
||||
})),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
},
|
||||
"prior attributes": {
|
||||
&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Computed: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"boz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bonjour"),
|
||||
"bar": cty.StringVal("petit dejeuner"),
|
||||
"baz": cty.StringVal("grande dejeuner"),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bonjour"),
|
||||
"bar": cty.StringVal("petit dejeuner"),
|
||||
"baz": cty.StringVal("grande dejeuner"),
|
||||
"boz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
},
|
||||
"prior nested single": {
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"foo": {
|
||||
Nesting: configschema.NestingSingle,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("beep"),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("beep"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"prior nested list": {
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"foo": {
|
||||
Nesting: configschema.NestingList,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.ListVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("bap"),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("blep"),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.ListVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("bap"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("blep"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"prior nested map": {
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"foo": {
|
||||
Nesting: configschema.NestingMap,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.NullVal(cty.String),
|
||||
"baz": cty.StringVal("boop"),
|
||||
}),
|
||||
"b": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("blep"),
|
||||
"baz": cty.NullVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.UnknownVal(cty.String),
|
||||
"baz": cty.StringVal("boop"),
|
||||
}),
|
||||
"b": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("blep"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"prior nested set": {
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"foo": {
|
||||
Nesting: configschema.NestingSet,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("blep"),
|
||||
"baz": cty.NullVal(cty.String),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.NullVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("blep"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"sets differing only by unknown": {
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"foo": {
|
||||
Nesting: configschema.NestingSet,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.NullVal(cty.String),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.UnknownVal(cty.String),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"prior nested list with dynamic": {
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"foo": {
|
||||
Nesting: configschema.NestingList,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.DynamicPseudoType,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.TupleVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.NullVal(cty.String),
|
||||
"baz": cty.NumberIntVal(8),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.TupleVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.UnknownVal(cty.String),
|
||||
"baz": cty.NumberIntVal(8),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"prior nested map with dynamic": {
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"foo": {
|
||||
Nesting: configschema.NestingMap,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"bar": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"baz": {
|
||||
Type: cty.DynamicPseudoType,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.ObjectVal(map[string]cty.Value{
|
||||
"a": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("beep"),
|
||||
"baz": cty.NullVal(cty.DynamicPseudoType),
|
||||
}),
|
||||
"b": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.NumberIntVal(8),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.ObjectVal(map[string]cty.Value{
|
||||
"a": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("beep"),
|
||||
"baz": cty.UnknownVal(cty.DynamicPseudoType),
|
||||
}),
|
||||
"b": cty.ObjectVal(map[string]cty.Value{
|
||||
"bar": cty.StringVal("boop"),
|
||||
"baz": cty.NumberIntVal(8),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
} {
|
||||
t.Run(n, func(t *testing.T) {
|
||||
got := SetUnknowns(tc.Val, tc.Schema)
|
||||
if !got.RawEquals(tc.Expected) {
|
||||
t.Fatalf("\nexpected: %#v\ngot: %#v\n", tc.Expected, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package objchange
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
// AllAttributesNull constructs a non-null cty.Value of the object type implied
|
||||
// by the given schema that has all of its leaf attributes set to null and all
|
||||
// of its nested block collections set to zero-length.
|
||||
//
|
||||
// This simulates what would result from decoding an empty configuration block
|
||||
// with the given schema, except that it does not produce errors
|
||||
func AllAttributesNull(schema *configschema.Block) cty.Value {
|
||||
vals := make(map[string]cty.Value)
|
||||
ty := schema.ImpliedType()
|
||||
|
||||
for name := range schema.Attributes {
|
||||
aty := ty.AttributeType(name)
|
||||
vals[name] = cty.NullVal(aty)
|
||||
}
|
||||
|
||||
for name, blockS := range schema.BlockTypes {
|
||||
aty := ty.AttributeType(name)
|
||||
|
||||
switch blockS.Nesting {
|
||||
case configschema.NestingSingle:
|
||||
// NestingSingle behaves like an object attribute, which decodes
|
||||
// as null when it's not present in configuration.
|
||||
vals[name] = cty.NullVal(aty)
|
||||
default:
|
||||
// All other nesting types decode as "empty" when not present, but
|
||||
// empty values take different forms depending on the type.
|
||||
switch {
|
||||
case aty.IsListType():
|
||||
vals[name] = cty.ListValEmpty(aty.ElementType())
|
||||
case aty.IsSetType():
|
||||
vals[name] = cty.SetValEmpty(aty.ElementType())
|
||||
case aty.IsMapType():
|
||||
vals[name] = cty.MapValEmpty(aty.ElementType())
|
||||
case aty.Equals(cty.DynamicPseudoType):
|
||||
// We use DynamicPseudoType in situations where there's a
|
||||
// nested attribute of DynamicPseudoType, since the schema
|
||||
// system cannot predict the final type until it knows exactly
|
||||
// how many elements there will be. However, since we're
|
||||
// trying to behave as if there are _no_ elements, we know
|
||||
// we're producing either an empty tuple or empty object
|
||||
// and just need to distinguish these two cases.
|
||||
switch blockS.Nesting {
|
||||
case configschema.NestingList:
|
||||
vals[name] = cty.EmptyTupleVal
|
||||
case configschema.NestingMap:
|
||||
vals[name] = cty.EmptyObjectVal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// By the time we get down here we should always have set a value.
|
||||
// If not, that suggests a missing case in the above switches.
|
||||
if _, ok := vals[name]; !ok {
|
||||
panic(fmt.Sprintf("failed to create empty value for nested block %q", name))
|
||||
}
|
||||
}
|
||||
|
||||
return cty.ObjectVal(vals)
|
||||
}
|
||||
Loading…
Reference in new issue