-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
command/format: Correctly quote diff object keys #30766
Conversation
When rendering a diff, we should quote object attribute names if the string representation is not a valid identifier. While this is not strictly necessary, it makes the diff output more closely resemble the configuration language, which is less confusing. This commit applies to both top-level schema attributes and any object value attributes. We use a simplistic "%q" Go format string to quote the strings, which is not strictly identical to HCL's quoting requirements, but is the pattern used elsewhere in HCL and Terraform. Co-Authored-By: Katy Moe <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
This PR seems to break the representation of ~ tags = {
+ "\"test.io/foo\"" = "my"
+ "\"test.io/bar\"" = "test"
# (8 unchanged elements hidden)
} |
@stevehipwell Thanks for the note! If those two keys in your example are strings containing escaped quotes, then this behaviour is correct. This patch is intended to make the diff output more closely represent the HCL representation of a value. Writing the already-quoted value If that behaviour is not what you're describing, I'm unable to reproduce the problem, so filing a separate issue would help us investigate. |
@alisdair sorry I forgot the input values, they were as follows and didn't have any escaped quotes. They were also passing through a variable typed as locals {
tags = {
"test.io/foo" = "my"
"test.io/bar" = "test"
}
} You can replicate this behaviour by using the following simple object to set the tags on an AWS resource (or other resource accepting locals {
tags = {
foo = "my"
"bar" = "test"
"foo/bar" = "my-test"
}
} Based on this test we can see that map keys with characters that HCL doesn't support in keys are being treated differently to keys without special character and that it's not the wrapping of the key with As |
@stevehipwell After some more poking around I found a reproduction. It seems like this only happens on update, and not on create, which is why I missed it before. Tracking in #30854, thanks for the report! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
This is a port of #25443 to the new diff renderer.
Fixes #21749
When rendering a diff, we should quote object attribute names if the string representation is not a valid identifier. While this is not
strictly necessary, it makes the diff output more closely resemble the configuration language, which is less confusing.
This commit applies to both top-level schema attributes and any object value attributes. We use a simplistic
"%q"
Go format string to quote the strings, which is not strictly identical to HCL's quoting requirements,but is the pattern used elsewhere in HCL and Terraform.