terraform
terraform copied to clipboard
Terraform fmt ignores tfvars
Terraform Version
0.9.11
Expected Behavior
As per documentation:
rewrite Terraform configuration files to a canonical format and style.
Actual Behavior
Only tf
files are formatted.
Steps to Reproduce
-
terraform fmt -list=true -write=false ./dir
dir/main.tf
dir/variables.tf
Specifying the absolute path works for that file.
-
terraform fmt -list=true -write=false ./dir/terraform.tfvars
dir/terraform.tfvars
why is something so simple to fix not fixed yet?
And also, why does terraform fmt
place new lines in all tfvars ?
.tfvars
files are not considered to be "part of the configuration" strictly speaking (they come from the command line), but I can see that in certain cases they behave as such and so it shouldn't hurt to format them if they happen to be in the same directory as the .tf
files (which is not required, but common).
The configuration-language-related parts of Terraform are currently in a state of flux as we prepare for the next release, but we can investigate this once the dust has settled from that release and, in particular, terraform fmt
will then be using the formatter from the new HCL version which should be better-behaved.