prior may be unknown when planning data sources

While the proposed plan value for managed resource is only a suggestion,
deferred data sources must be completely planed by core, hence set
appropriate unknown values. We do this by using a prior unknown, which
must be taken into account by all nested types.
pull/36663/head
James Bardin 1 year ago
parent 9ac4b3a62b
commit 56137f3b6c

@ -229,7 +229,6 @@ func proposedNewNestingList(schema nestedSchema, prior, config cty.Value) cty.Va
func proposedNewNestingMap(schema nestedSchema, prior, config cty.Value) cty.Value {
newV := config
newVals := map[string]cty.Value{}
if config.IsNull() || !config.IsKnown() || config.LengthInt() == 0 {
@ -239,7 +238,7 @@ func proposedNewNestingMap(schema nestedSchema, prior, config cty.Value) cty.Val
}
cfgMap := config.AsValueMap()
// prior may be null or empty
// prior may be null, empty or unknown
priorMap := map[string]cty.Value{}
if !prior.IsNull() && prior.IsKnown() && prior.LengthInt() > 0 {
priorMap = prior.AsValueMap()
@ -248,10 +247,13 @@ func proposedNewNestingMap(schema nestedSchema, prior, config cty.Value) cty.Val
for name, configEV := range cfgMap {
priorEV, inPrior := priorMap[name]
if !inPrior {
// If there is no corresponding prior element then
// we just take the config value as-is.
newVals[name] = configEV
continue
// if the prior cty.Map value was unknown the map won't have any
// keys, so generate an unknown value.
if !prior.IsKnown() {
priorEV = cty.UnknownVal(configEV.Type())
} else {
priorEV = cty.NullVal(configEV.Type())
}
}
newVals[name] = proposedNewBlockOrObject(schema, priorEV, configEV)
@ -339,9 +341,7 @@ func proposedNewAttributes(attrs map[string]*configschema.Attribute, prior, conf
} else {
priorV = prior.GetAttr(name)
}
configV := config.GetAttr(name)
var newV cty.Value
switch {
// required isn't considered when constructing the plan, so attributes

@ -954,7 +954,7 @@ func TestProposedNew(t *testing.T) {
}),
"c": cty.ObjectVal(map[string]cty.Value{
"bar": cty.StringVal("bosh"),
"baz": cty.NullVal(cty.List(cty.String)),
"baz": cty.NullVal(cty.DynamicPseudoType),
}),
}),
"bloop": cty.ObjectVal(map[string]cty.Value{
@ -1920,7 +1920,7 @@ func TestProposedNew(t *testing.T) {
Attributes: map[string]*configschema.Attribute{
"map": {
NestedType: &configschema.Object{
Nesting: configschema.NestingList,
Nesting: configschema.NestingMap,
Attributes: map[string]*configschema.Attribute{
"foo": {
Type: cty.String,
@ -1942,7 +1942,7 @@ func TestProposedNew(t *testing.T) {
})),
}),
"map": cty.Map(cty.Object(map[string]cty.Type{
"list": cty.List(cty.Object(map[string]cty.Type{
"map": cty.List(cty.Object(map[string]cty.Type{
"foo": cty.String,
})),
})),
@ -1960,11 +1960,11 @@ func TestProposedNew(t *testing.T) {
}),
"map": cty.MapVal(map[string]cty.Value{
"one": cty.ObjectVal(map[string]cty.Value{
"list": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"map": cty.MapVal(map[string]cty.Value{
"one": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("a"),
}),
cty.ObjectVal(map[string]cty.Value{
"two": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("b"),
}),
}),
@ -1984,11 +1984,11 @@ func TestProposedNew(t *testing.T) {
}),
"map": cty.MapVal(map[string]cty.Value{
"one": cty.ObjectVal(map[string]cty.Value{
"list": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"map": cty.MapVal(map[string]cty.Value{
"one": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("a"),
}),
cty.ObjectVal(map[string]cty.Value{
"two": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("b"),
}),
}),

Loading…
Cancel
Save