summaryrefslogtreecommitdiff
path: root/cmd/hcldec
diff options
context:
space:
mode:
authorMartin Atkins <mart@degeneration.co.uk>2018-08-22 11:52:40 -0700
committerMartin Atkins <mart@degeneration.co.uk>2018-08-22 11:52:40 -0700
commitb82170e9412cfb0052b5029d870d0f4216d21bcd (patch)
tree56c02ec1193a505275b95cb8bb00bd3fa1ca2795 /cmd/hcldec
parentd6049c2a047e81ac7e8b7934ae479898387f1bbc (diff)
hcldec: Handle or forbid cty.DynamicPseudoType attributes in nested blocks
Our BlockList, BlockSet, and BlockMap specs all produce cty collection values, which require all elements to have a homogeneous type. If the nested spec contained an attribute of type cty.DynamicPseudoType, that would create the risk of each element having a different type, which would previously have caused decoding to panic. Now we either handle this during decode (BlockList, BlockSet) or forbid it outright (BlockMap) to prevent that crash. BlockMap could _potentially_ also handle this during decode, but that would require a more significant reorganization of its implementation than I want to take on right now, and decoding dynamically-typed values inside collections is an edge case anyway.
Diffstat (limited to 'cmd/hcldec')
-rw-r--r--cmd/hcldec/spec.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/cmd/hcldec/spec.go b/cmd/hcldec/spec.go
index b62f05b..c8b90d3 100644
--- a/cmd/hcldec/spec.go
+++ b/cmd/hcldec/spec.go
@@ -394,6 +394,15 @@ func decodeBlockMapSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Dia
return errSpec, diags
}
+ if hcldec.ImpliedType(spec).HasDynamicTypes() {
+ diags = append(diags, &hcl.Diagnostic{
+ Severity: hcl.DiagError,
+ Summary: "Invalid block_map spec",
+ Detail: "A block_map spec may not contain attributes with type 'any'.",
+ Subject: body.MissingItemRange().Ptr(),
+ })
+ }
+
return spec, diags
}