I personally prefer variable definitions on a single line - I find it far more readable when there are a lot of variables in a file.
Ex.
variable "instance_count" { default = 1 }
variable "instance_size" { default = 1 }
variable "instance_type" { default = 1 }
vs.
variable "instance_count" {
default = 1
}
variable "instance_size" {
default = 1
}
variable "instance_type" {
default = 1
}
Terraform does the latter by default. It would be great if terraform fmt had an option that would let us pick between different formatting style based on preference.
Hi @MaxFlanders! Thanks for this request.
terraform fmt's style is nobody's favorite, but yet it's everybody's favorite. The purpose of this tool is to bless one specific way of formatting Terraform code as the "standard" way. To make it configurable would defeat the purpose of it.
I understand that this particular aspect of the built-in formatting doesn't match how you would've written it, but ultimately this tool has to make _some_ decision, and no decision will be perfect for everyone.
Even popular opinionated tools such as prettier are configurable.
The behavior of fmt that, for me, is unconscionable is the gratuitous whitespace added in order to align property values. The addition or removal of one property can add or remove gratuitous whitespace in a multitude of lines. I know of no other language or style guide intended to be used by teams of devs that encourages gratuitous changes. Please provide an option.
Just my opinion, but I think the property value alignment formatting creates unneeded git history churn, makes it harder to read diffs, and harder to follow git blames.
The implementation of terraform fmt coming in Terraform v0.12 will now leave blocks using the single-argument-on-one-line alternative style unchanged. Indeed, in general it will avoid adding and removing newlines and will focus on indentation, alignment, and spacing instead.
We do not intend to make any of the alignment decisions optional. As some have noted, there is a tradeoff here between readability of configuration at rest vs. readability of configuration changes expressed as line-oriented diffs. Terraform chooses to prioritize readability of changes at rest, which is the same decision made by the formatter in the Go programming language. If particular teams disagree with the idiomatic layout of Terraform configuration they can elect to not use terraform fmt at all, or use a different tool.
If particular teams disagree with the idiomatic layout of Terraform configuration they can elect to not use
terraform fmtat all, or use a different tool.
Does anyone know off hand if there are any other tools out there? The change proposed of single line arguments would work for me, but was just wondering if there actually were any other tools out there for the time being?
I see you inherit the same closed mindness as Go regarding valid suggestions that would improve your integration with VCS tools used by the great majority of your users. Forcing diffs across multiple lines on single line changes, polluting the history of every single project, could have been a mistake, being inflexible about it is just plain stupid.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Even popular opinionated tools such as prettier are configurable.
The behavior of fmt that, for me, is unconscionable is the gratuitous whitespace added in order to align property values. The addition or removal of one property can add or remove gratuitous whitespace in a multitude of lines. I know of no other language or style guide intended to be used by teams of devs that encourages gratuitous changes. Please provide an option.