hcl icon indicating copy to clipboard operation
hcl copied to clipboard

Add support for dynamic blocks when using ',remain' tag

Open jlarfors opened this issue 3 years ago • 1 comments

Background:

We wanted a map[string]cty.Value from HCL. We tried using a map in cty but that means all the values should be of the same type, e.g. this fails:

fields = {
  my_bool = false
  my_string = "string"
}

So we resorted to using a block fields { ... } with the ,remain tag and the following go struct:

type DataFields struct {
	Values map[string]cty.Value `hcl:",remain"`
}

And now we can do:

fields {
  my_bool = true
  my_string = "string"
}

However this fails inside the dynamic block because the body.JustAttributes() method does not respect the scope/iteration inside a dynamic block. This small PR addresses this and would be great if you accept this PR.

jlarfors avatar Jun 10 '21 05:06 jlarfors

CLA assistant check
All committers have signed the CLA.

hashicorp-cla avatar Jun 10 '21 05:06 hashicorp-cla