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

feat: Change terraform-format to support both Terraform and OpenTofu packages #419

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sestrella
Copy link
Contributor

@sestrella sestrella commented Mar 27, 2024

Fixes #418

@sestrella sestrella changed the title Create different hooks for Terraform and OpenTofu format feat: Create different hooks for Terraform and OpenTofu format Mar 27, 2024
@sestrella sestrella force-pushed the terraform_and_opentofu_format branch from 7b901bb to 59000fb Compare March 27, 2024 16:32
.github/workflows/ci.yaml Outdated Show resolved Hide resolved
modules/hooks.nix Outdated Show resolved Hide resolved
@sestrella sestrella force-pushed the terraform_and_opentofu_format branch 2 times, most recently from 50e6472 to b112f79 Compare April 3, 2024 16:53
terraform-fmt = pkgs.writeScriptBin "terraform-fmt" ''
#!/usr/bin/env bash

opentofu_or_terraform() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totoroot Based on our discussion, I made a few changes to the existing terraform-format. For the time being, I feel it would be easier to alter the existing hook to work with both OpenTofu and Terraform. End users can choose whether to use OpenTofu (the default) or alter the package to Terraform, as shown in this example:

https://github.com/sestrella/test-pre-commit-hooks.nix/blob/main/devenv.nix

I'm planning to update the PR title and the issue accordingly.

@sestrella sestrella changed the title feat: Create different hooks for Terraform and OpenTofu format feat: Change terraform-format to support both Terraform and OpenTofu packages Apr 5, 2024
@sestrella sestrella force-pushed the terraform_and_opentofu_format branch from e752c46 to 4696ed5 Compare December 5, 2024 04:04
@sestrella
Copy link
Contributor Author

sestrella commented Dec 5, 2024

@domenkozar I just resolved the conflicts on this branch and updated the repo I was using for testing; so far, it appears to be working properly:

0000.02: terraform-format.........................................................Failed
0000.02: - hook id: terraform-format
0000.02: - exit code: 1
0000.02: 
0000.02: main.tf
0000.02: --- old/main.tf
0000.02: +++ new/main.tf
0000.02: @@ -1,4 +1,4 @@
0000.02:  locals {
0000.02: -  foo     = 1
0000.02: -  bar   = 2
0000.02: +  foo = 1
0000.02: +  bar = 2
0000.02:  }
0000.02: test.tf
0000.02: --- old/test.tf
0000.02: +++ new/test.tf
0000.02: @@ -1,4 +1,4 @@
0000.02:  locals {
0000.02: -  zoo = 1
0000.02: +  zoo    = 1
0000.02:    asdasd = 2
0000.02:  }
0000.02: Run 'terraform fmt -recursive' to format the code

Would you mind taking a look, please?

Reference: https://github.com/sestrella/test-pre-commit-hooks.nix/actions/runs/12173105536/job/33952913600

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.

Change terraform-format to support both Terraform and OpenTofu packages
2 participants