Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addresses #15304. There are a couple ways to solve this, but I chose to modify the
fmt
command with a-check
flag that produces the desired behavior.I chose not to put this functionality in
github.com/hashicorp/hcl/hcl/fmtcmd
, because that would have required a change to the API. That has broader implications. If the consensus is that said functionality would be useful outside ofterraform fmt
, I can move the logic to thehcl
lib.Alternatively,
fmt
could have been updated to alter its return code without the-check
flag - likegofmt
. However, as pointed out, that changes the current behavior which could have a downstream impact. Additionally, the default semantics ofterraform fmt
are different fromgofmt
. Namely,-write
defaults totrue
withterraform fmt
, butfalse
withgofmt
. Unless that default were changed (which seems like bad idea), you would need to runterraform fmt -write=false
to achieve the requested effect.terraform fmt -check
seems simpler and more intuitive to me.