From cd83e6108d621d209ad4a5ddb59b6ae6efe86b85 Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Fri, 2 Aug 2019 16:04:45 -0400 Subject: [PATCH 1/2] Fixes issue where attribute in nested is not of list type/is invalid and would panic --- lang/blocktoattr/variables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/blocktoattr/variables.go b/lang/blocktoattr/variables.go index b172805a0..f2e89861e 100644 --- a/lang/blocktoattr/variables.go +++ b/lang/blocktoattr/variables.go @@ -33,7 +33,7 @@ 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() { synthSchema := SchemaForCtyElementType(attrS.Type.ElementType()) vars = append(vars, walkVariables(child.Node, child.Body(), synthSchema)...) } From 234c1c482a7bfc74a389da8d0f550ec88185ebce Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Fri, 2 Aug 2019 16:15:18 -0400 Subject: [PATCH 2/2] Add a comment --- lang/blocktoattr/variables.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lang/blocktoattr/variables.go b/lang/blocktoattr/variables.go index f2e89861e..59ba47bf4 100644 --- a/lang/blocktoattr/variables.go +++ b/lang/blocktoattr/variables.go @@ -34,6 +34,8 @@ func walkVariables(node dynblock.WalkVariablesNode, body hcl.Body, schema *confi 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.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)...) }