-
Notifications
You must be signed in to change notification settings - Fork 640
Description
Description
I am currently working on a proof of concept tool that could help practitioners migrate their Terraform HCL configurations from null_resource
resource blocks to terraform_data
resource blocks (as well as adding moved
blocks). Renaming the block types in-place works great, however similar functionality is not available for hclwrite.Attribute
to update the attribute name in-place. Currently the workaround seems something like:
body.RemoveAttribute("triggers")
body.SetAttributeRaw("triggers_replace", triggersAttribute.Expr().BuildTokens(nil))
However that will cause the attribute and its expression to be moved to the bottom of the same block, causing unnecessary configuration churn.
Proposal
Similar to the (*hclwrite.Block).SetType()
method added in #340, create a new (*hclwrite.Attribute).SetName()
method, e.g.
func (*Attribute) SetName(name string)
That only replaces the underlying name
node in the AST. I have verified this locally and will submit the small addition for consideration. Thank you!