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

Add support for formatting .tfbackend files #36570

Closed
wants to merge 4 commits into from

Conversation

SarahFrench
Copy link
Member

Fixes #36564

Target Release

1.12.x

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@SarahFrench SarahFrench marked this pull request as ready for review February 24, 2025 18:27
@SarahFrench SarahFrench requested a review from a team as a code owner February 24, 2025 18:27
@jbardin
Copy link
Member

jbardin commented Feb 24, 2025

I don't think we have a defined .tfbackend file format, it's definitely not an extension used by the CLI. We could say that this PR is defining that as a format, but wonder if this is standard enough to actually be used in most existing configurations.

@radeksimko
Copy link
Member

I recall conversation about this and the main take away from it for me was that the format is driven or at least constrained still largely by HCL1, whereas the rest of the codebase (including fmt) and all the tooling such as Terraform LS is HCL2 based.

The two language editions looks similar enough but are quite different under the hood, so I think it makes it difficult/impossible to guarantee that output from HCL2 would still be compatible with HCL1 parser. It's certainly possible it will be if it concerns just whitespaces it will be but I think we ended up overloading fmt for much more than just whitespace changes so I think that compatibility likelihood goes down with that also.

This is also one of the reasons LS does not support that file format today. We have at least standardised the file name, so that editors can associate that with HCL and highlight correctly and someone can create an extension/LS which does more than just highlighting.

@SarahFrench
Copy link
Member Author

SarahFrench commented Feb 24, 2025

Would the advice then be to not use the *.tfbackend filename? This is recommended in the documentation. If *.tfvars also works and is technically more correct w.r.t formatting, should we update the documentation?

@radeksimko
Copy link
Member

It's true tfvars is probably closest similar format but it's still not the same. Also naming something tfvars then suggests it can be leveraged as variables file - which may not always be the case.

The two formats have different purpose and different constraints (I believe tfbackend entries basically map to backend CLI flags and the file config is more of an afterthought, CLI flags were first) and they are each based on a different version of HCL.

I posted one known workaround in #36564 (comment)

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

Successfully merging this pull request may close these issues.

terraform fmt should accept .tfbackend files
3 participants