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
I'm using hclwrite to print some Terraform resource arguments that are maps. I'm having trouble getting them to span multiple lines using the higher-level hclwrite functions. Similar to #347, I'm wondering if this can be achieved with SetAttributeValue or if I'll need to resort to SetAttributeRaw.
The first uses SetAttributeValue on the entire map value. This is the exact syntax I'm looking for except it is all on one line rather than separate lines per key-value pair.
The second uses AppendNewBlock and separate SetAttributeValues per pair. This is missing the equals sign as well as quoting around the first key, causing it to be treated as a division expression.
The third uses SetAttributeRaw on the entire contents of the map. This outputs what I want, I'm just wondering if theres a simpler way.
As mentioned, this can be achieved with my third attempt in the gist plus some extra logic around optionally quoting the keys which would be trivial to implement.
Is there an easier way to achieve this with hclwrite or should I continue with SetAttributeRaw or perhaps some other utility function like hclwrite.Format? Any input would be greatly appreciated. Thanks!
The text was updated successfully, but these errors were encountered:
I have similar problem but for keep multiline format for list element. I want to append a new element to an existing hcl list programmatically. Any recommendations for how to achieve this?
@rifelpet We recently changed the behaviour of hclwrite in #372 to always generate multiple lines for non-empty maps and objects. This was released in v2.5.0.
I'm closing this issue as I think it's addressed, but feel free to reopen if I'm mistaken.
I'm using hclwrite to print some Terraform resource arguments that are maps. I'm having trouble getting them to span multiple lines using the higher-level hclwrite functions. Similar to #347, I'm wondering if this can be achieved with
SetAttributeValue
or if I'll need to resort toSetAttributeRaw
.This gist shows my three attempts:
SetAttributeValue
on the entire map value. This is the exact syntax I'm looking for except it is all on one line rather than separate lines per key-value pair.AppendNewBlock
and separateSetAttributeValue
s per pair. This is missing the equals sign as well as quoting around the first key, causing it to be treated as a division expression.SetAttributeRaw
on the entire contents of the map. This outputs what I want, I'm just wondering if theres a simpler way.HCL Template
The generated HCL from the above gist:
The desired HCL:
As mentioned, this can be achieved with my third attempt in the gist plus some extra logic around optionally quoting the keys which would be trivial to implement.
Is there an easier way to achieve this with hclwrite or should I continue with
SetAttributeRaw
or perhaps some other utility function likehclwrite.Format
? Any input would be greatly appreciated. Thanks!The text was updated successfully, but these errors were encountered: