Skip to content
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

terraform fmt should accept .tfbackend files #36564

Open
thiagowfx opened this issue Feb 21, 2025 · 4 comments
Open

terraform fmt should accept .tfbackend files #36564

thiagowfx opened this issue Feb 21, 2025 · 4 comments
Labels
enhancement new new issue not yet triaged

Comments

@thiagowfx
Copy link

Terraform Version

% terraform version
Terraform v1.10.4

Use Cases

It should be possible to run terraform fmt on .tfbackend files, just like it is possible to do so in .tfvars files.

As of now:

$ terraform fmt a.tfbackend
│ Error: Only .tf, .tfvars, and .tftest.hcl files can be processed with terraform fmt

Wherein:

$ cat a.tfbackend
a = "foo"
b      = "bar"

.tfbackend is very similar to .tfvars as per the official docs.

The example docs also show the files nicely formatted (the equal signs are vertically aligned), suggesting that it is the intent.

Attempted Solutions

terraform fmt a.tfbackend does not work.

Renaming it to a.tfvars and then running terraform fmt a.tfvars works.

Proposal

Make terraform fmt accept *.tfbackend files, similarly to .tfvars.

References

No response

@radeksimko
Copy link
Member

You can still format a file regardless of its name by piping its contents into fmt. For example:

cat any-file.any-ext | terraform fmt -

Bear in mind though that the file format is based on the earlier generation of HCL (1) and so there is no guarantee that it would always produce compatible output or be able to format it.

@SarahFrench SarahFrench removed their assignment Feb 24, 2025
@yermulnik
Copy link

yermulnik commented Feb 24, 2025

@radeksimko While this hint makes sense, it seems to be sort of natural for terraform fmt to support .tfbackend files too:

Usage: terraform [global options] fmt [options] [target...]

Rewrites all Terraform configuration files to a canonical format. […]

Though looking at the conversation in #36570 I seem to think implementation isn't going to be an easy thing =(

Do you by any chance know whether the .tfbackend has existed long before or is it something new? Asking as I actually TIL'ed about it when @thiagowfx filed another PR about it in the other repo. Thanks.

@yermulnik
Copy link

Looking at bb86860 from 2021, this looks to be a long-existed feature which I have never come across, though which was described to be using .hcl files before that commit.

@crw
Copy link
Contributor

crw commented Feb 25, 2025

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. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants