Terraform fmt tfvars - split long line array into multiple lines
Terraform Version
% terraform version
Terraform v1.7.2
on darwin_arm64
Use Cases
Suppose we have a tfvars file with the following content, where a variable is a array of a type and is a long line
% cat example.tfvars
var1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
Running terraform fmt on this should ideally split it into multiple lines like below for readability
% cat formatted.tfvars
var1 = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40
]
Both versions are properly formatted as per terraform fmt -check
The point at which this is split can be decided based on line length or number of array items
Splitting into multiple lines helps with readability and easily eyeing diff in scm when objects are removed or added to the list
Attempted Solutions
Tried modifying the tfvars files by introducing a new line in the middle of array to see if it splits all others into multiple lines, but it didn't
Proposal
No response
References
- #22703 A more generic version of this
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions.
To set expectations, this is unlikely to be changed without a big re-think of the purpose of fmt - for all intents and purposes, the fmt command is "working as designed" right now. However, it is useful for us to see the level of support for issues such as this when contemplating any future changes.
Thanks again!