Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hclwrite: Consider Attribute Rename Support #680

Open
bflad opened this issue May 23, 2024 · 0 comments · May be fixed by #681
Open

hclwrite: Consider Attribute Rename Support #680

bflad opened this issue May 23, 2024 · 0 comments · May be fixed by #681

Comments

@bflad
Copy link

bflad commented May 23, 2024

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!

bflad added a commit that referenced this issue May 23, 2024
Reference: #340
Reference: #680

Similar to `(*hclwrite.Block).SetType()`, this new method enables in-place renaming of an attribute.
@bflad bflad linked a pull request May 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant