Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Terraform formatter step#959

Closed
carhartl wants to merge 7 commits into
diffplug:mainfrom
carhartl:terraform-formatter-step
Closed

Add Terraform formatter step#959
carhartl wants to merge 7 commits into
diffplug:mainfrom
carhartl:terraform-formatter-step

Conversation

@carhartl

@carhartl carhartl commented Oct 8, 2021

Copy link
Copy Markdown
Contributor

This PR adds the ability for Spotless to test for/enforce consistent formatting for Terraform files (.tf, .tfvars).

The step shells out to the external terraform fmt command, the implementation being similar to the existing Black step.

I found that often times terraform files are part of an application repository, thus enhancing Spotless in order to be able to use a single build tool/interface for keeping formatting for these sources consistent.

Here's a repository I used for doing integration testing of the gradle plugin: https://github.com/carhartl/spotless-terraform-test

See https://www.terraform.io/docs/cli/commands/fmt.html for more information regarding Terraform formatting.

The step shells out to the external `terraform fmt` command, the
implementation being similar to the existing Black step.

This step is supposed to ensure consistent, conventional formatting for
.tf and .tfvars files.
@nedtwigg

nedtwigg commented Oct 8, 2021

Copy link
Copy Markdown
Member

Looks great! I'm gonna give this 24 hrs in case anybody else has comments, then I'll merge and release.

@nedtwigg

nedtwigg commented Oct 8, 2021

Copy link
Copy Markdown
Member

Actually, just one missing piece: the feature matrix in the root README. It's a bit tricky, the actual text of the table is rendered by an embedded freshmark script above it (edit the comment, run spotlessApply, and it will render the table), see this PR for an example.

@carhartl

carhartl commented Oct 9, 2021

Copy link
Copy Markdown
Contributor Author

#949 looks interesting, doesn’t that mean instead of this entire PR we could use the native cmd capability instead for formatting terraform files? Must have overlooked this..

@nedtwigg

nedtwigg commented Oct 9, 2021

Copy link
Copy Markdown
Member

You are correct, another way to accomplish this PR would be to port NativeCmd to plugin-gradle's FormatExtension, rather than have special-purpose terraform stuff. I have no preference either way.

@carhartl

Copy link
Copy Markdown
Contributor Author

I think having NativeCmd available in plugin-gradle will provide more value overall, and add less code, so I'm giving this a try, preparing a new PR..

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.

2 participants