Skip to content

Commit

Permalink
[scripts] Fix terraform lint
Browse files Browse the repository at this point in the history
Summary:
When reviewing D9877 I realized that terraform format lint doesn't work in pre-commit hook. Fixed this.
Also changed it to auto-format instead of failing.

Test Plan:
Made some formatting errors in terraform files, git staged them, and ran `yarn lint-staged`. It fixed them.

Output of `terraform_pre_commit.sh` (the `modules/shared/dynamodb.tf` was the file that was reformatted):
```
ᐅ ./scripts/terraform_pre_commit.sh
Formatting terraform...
modules/shared/dynamodb.tf
Validating 'dev' terraform configuration...
Success! The configuration is valid.

Validating 'remote' terraform configuration...
Success! The configuration is valid.
```

Reviewers: varun, wyilio

Reviewed By: varun

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D9958
  • Loading branch information
barthap committed Dec 1, 2023
1 parent 476e0b3 commit ea2bcfa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scripts/terraform_pre_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

set -e

cd services/terraform
echo "formatting services/terraform..."
terraform fmt -check
echo "validating services/terraform..."
terraform validate
echo "done formatting and validating"
cd services/terraform/
echo "Formatting terraform..."
terraform fmt -recursive

for cfg in dev remote; do
pushd "$cfg" >/dev/null
echo "Validating '$cfg' terraform configuration..."
terraform validate
popd >/dev/null
done

echo "Done formatting and validating terraform"

0 comments on commit ea2bcfa

Please sign in to comment.