Skip to content

Commit

Permalink
Enable formatting of modules requiring TF 0.15 or TF 1. (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Jun 25, 2021
1 parent e921f48 commit 5c5abec
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions modules/terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ terraform/fmt:
ifeq ($(wildcard *.tf),)
@echo "* $@: No terraform files detected"
else
@{ command -v terraform-0.13 && command -v terraform-0.14; } >/dev/null || { echo "* $@ requires binaries named terraform-0.13 and terraform-0.14" && false; }
@{ command -v terraform-0.13 && \
command -v terraform-0.14 && \
command -v terraform-0.15 && \
command -v terraform-1 \
; } >/dev/null || { echo "* $@ requires binaries named terraform-0.13, terraform-0.14, terraform-0.15, and terraform-1" && false; }
@ # vert exits non-zero if any of the versions are not acceptable, so `|| [[ -n "$VERSION" ]]` for a real error check
@TF12=0.12.29; \
TF13=$$(terraform-0.13 version --json | jq -r .terraform_version); \
TF14=$$(terraform-0.14 version --json | jq -r .terraform_version); \
VERSION=$$(vert -s "$$(terraform-config-inspect --json . | jq -r '.required_core[]')" "$$TF12" "$$TF13" "$$TF14" | head -1) || [[ -n "$$VERSION" ]]; \
@TF012=0.12.29; \
TF013=$$(terraform-0.13 version --json | jq -r .terraform_version); \
TF014=$$(terraform-0.14 version --json | jq -r .terraform_version); \
TF015=$$(terraform-0.15 version --json | jq -r .terraform_version); \
TF1=$$(terraform-1 version --json | jq -r .terraform_version); \
VERSION=$$(vert -s "$$(terraform-config-inspect --json . | jq -r '.required_core[]')" "$$TF012" "$$TF013" "$$TF014" "$$TF015" "$$TF1" | head -1) || [[ -n "$$VERSION" ]]; \
VERSION=$${VERSION:0:4}; \
[[ $$VERSION =~ ^1 ]] && VERSION=1 || true; \
terraform-$${VERSION} fmt -recursive .
endif

Expand Down

0 comments on commit 5c5abec

Please sign in to comment.