You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
I'd like to use hclencoder with Terraform 0.12, but this version of terraform is a lot pickier about attributes vs blocks.
Due to the design of the configuration language decoder in Terraform v0.11 and earlier, it was in many cases possible to interchange the argument syntax (with =) and the block syntax (with just braces) when dealing with map arguments vs. nested blocks. However, this led to some subtle bugs and limitations, so Terraform v0.12 now requires consistent usage of argument syntax for arguments and nested block syntax for nested blocks.
The current hclencoder code treats all ObjectType blocks (i.e. all maps and structs) as nested blocks, rather than as attributes being assigned:
I'm not particularly familiar with HCL usage outside of Terraform, but at least in Terraform 0.12, it seems that maps and structs can be used either as attributes or as blocks. (I may be mistaken on this point, it may be that maps are always attributes and structs are always blocks, I've just started diving into the details of HCL in the last day or two, so please correct me if I'm wrong on this point.) It would be nice if hclencoder could distinguish between when to write an attribute vs a nested block.
// Sometimes desired behavior
Bar = {
abc = "def"
}
For reference, this is a more general version of the issue raised in #17 .
I think the best way forward here may be to add an additional hcle tag, to allow hclencoder to determine whether to treat a map/struct as an assignment or not, but, like I said, I'm relatively new to HCL, so I'm curious what other people think here.
The text was updated successfully, but these errors were encountered:
So, im back here in 2021 with an update. Basically all hashicorp tools have moved on to HCL2, but there isn't another great library that I've found for encoding structs to hcl text...
I've hacked the library in a couple ways that I will be the first to admit are straight up nasty. If you are interested, you can see my changes at https://github.com/jmcshane/hclencoder
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'd like to use hclencoder with Terraform 0.12, but this version of terraform is a lot pickier about attributes vs blocks.
The current hclencoder code treats all
ObjectType
blocks (i.e. all maps and structs) as nested blocks, rather than as attributes being assigned:I'm not particularly familiar with HCL usage outside of Terraform, but at least in Terraform 0.12, it seems that maps and structs can be used either as attributes or as blocks. (I may be mistaken on this point, it may be that maps are always attributes and structs are always blocks, I've just started diving into the details of HCL in the last day or two, so please correct me if I'm wrong on this point.) It would be nice if hclencoder could distinguish between when to write an attribute vs a nested block.
To be clear, in some circumstances, the code
should produce the block
but in others it should produce the assignment
For reference, this is a more general version of the issue raised in #17 .
I think the best way forward here may be to add an additional
hcle
tag, to allow hclencoder to determine whether to treat a map/struct as an assignment or not, but, like I said, I'm relatively new to HCL, so I'm curious what other people think here.The text was updated successfully, but these errors were encountered: