mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
fix ComputedKeys for nested blocks in shimmed cfg
The indexes were added out of order in the attribute keys
This commit is contained in:
parent
332010fd56
commit
43f0468829
@ -297,14 +297,14 @@ func newResourceConfigShimmedComputedKeys(obj cty.Value, schema *configschema.Bl
|
|||||||
i := 0
|
i := 0
|
||||||
for it := blockVal.ElementIterator(); it.Next(); i++ {
|
for it := blockVal.ElementIterator(); it.Next(); i++ {
|
||||||
_, subVal := it.Element()
|
_, subVal := it.Element()
|
||||||
subPrefix := fmt.Sprintf("%s.%s%d.", typeName, prefix, i)
|
subPrefix := fmt.Sprintf("%s%s.%d.", prefix, typeName, i)
|
||||||
keys := newResourceConfigShimmedComputedKeys(subVal, &blockS.Block, subPrefix)
|
keys := newResourceConfigShimmedComputedKeys(subVal, &blockS.Block, subPrefix)
|
||||||
ret = append(ret, keys...)
|
ret = append(ret, keys...)
|
||||||
}
|
}
|
||||||
case configschema.NestingMap:
|
case configschema.NestingMap:
|
||||||
for it := blockVal.ElementIterator(); it.Next(); {
|
for it := blockVal.ElementIterator(); it.Next(); {
|
||||||
subK, subVal := it.Element()
|
subK, subVal := it.Element()
|
||||||
subPrefix := fmt.Sprintf("%s.%s%s.", typeName, prefix, subK.AsString())
|
subPrefix := fmt.Sprintf("%s%s.%s.", prefix, typeName, subK.AsString())
|
||||||
keys := newResourceConfigShimmedComputedKeys(subVal, &blockS.Block, subPrefix)
|
keys := newResourceConfigShimmedComputedKeys(subVal, &blockS.Block, subPrefix)
|
||||||
ret = append(ret, keys...)
|
ret = append(ret, keys...)
|
||||||
}
|
}
|
||||||
|
@ -929,6 +929,58 @@ func TestNewResourceConfigShimmed(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "unknown in nested blocks",
|
||||||
|
Val: cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"bar": cty.ListVal([]cty.Value{
|
||||||
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"baz": cty.ListVal([]cty.Value{
|
||||||
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"list": cty.UnknownVal(cty.List(cty.String)),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
Schema: &configschema.Block{
|
||||||
|
BlockTypes: map[string]*configschema.NestedBlock{
|
||||||
|
"bar": {
|
||||||
|
Block: configschema.Block{
|
||||||
|
BlockTypes: map[string]*configschema.NestedBlock{
|
||||||
|
"baz": {
|
||||||
|
Block: configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"list": {Type: cty.List(cty.String),
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Nesting: configschema.NestingList,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Nesting: configschema.NestingList,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Expected: &ResourceConfig{
|
||||||
|
ComputedKeys: []string{"bar.0.baz.0.list"},
|
||||||
|
Raw: map[string]interface{}{
|
||||||
|
"bar": []interface{}{map[string]interface{}{
|
||||||
|
"baz": []interface{}{map[string]interface{}{
|
||||||
|
"list": "74D93920-ED26-11E3-AC10-0800200C9A66",
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"bar": []interface{}{map[string]interface{}{
|
||||||
|
"baz": []interface{}{map[string]interface{}{
|
||||||
|
"list": "74D93920-ED26-11E3-AC10-0800200C9A66",
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "null blocks",
|
Name: "null blocks",
|
||||||
Val: cty.ObjectVal(map[string]cty.Value{
|
Val: cty.ObjectVal(map[string]cty.Value{
|
||||||
|
Loading…
Reference in New Issue
Block a user