Merge pull request #22314 from hashicorp/pselle/double-dynamic

Fix panic on double dynamic blocks
This commit is contained in:
Pam Selle 2019-08-16 15:15:50 -04:00 committed by GitHub
commit e38d588cfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -33,7 +33,9 @@ func walkVariables(node dynblock.WalkVariablesNode, body hcl.Body, schema *confi
for _, child := range children {
if blockS, exists := schema.BlockTypes[child.BlockTypeName]; exists {
vars = append(vars, walkVariables(child.Node, child.Body(), &blockS.Block)...)
} else if attrS, exists := schema.Attributes[child.BlockTypeName]; exists && attrS.Type.ElementType().IsObjectType() {
} else if attrS, exists := schema.Attributes[child.BlockTypeName]; exists && attrS.Type.IsCollectionType() && attrS.Type.ElementType().IsObjectType() {
// ☝Check for collection type before element type, because if this is a mis-placed reference,
// a panic here will prevent other useful diags from being elevated to show the user what to fix
synthSchema := SchemaForCtyElementType(attrS.Type.ElementType())
vars = append(vars, walkVariables(child.Node, child.Body(), synthSchema)...)
}