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

Get Terraform version from dotfile in workflow #13

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions .github/workflows/continuous-integration-terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,42 @@ jobs:
- name: Check out code
uses: actions/checkout@v3

- name: Check for terraform version mismatch
- name: Get terraform version
id: get-terraform-version
run: |
DOTFILE_VERSION=$(cat .terraform-version)
TERRAFORM_IMAGE_REFERENCES=$(grep "uses: docker://hashicorp/terraform" .github/workflows/continuous-integration-terraform.yml | grep -v TERRAFORM_IMAGE_REFERENCES | wc -l | tr -d ' ')
if [ "$(grep "docker://hashicorp/terraform:${DOTFILE_VERSION}" .github/workflows/continuous-integration-terraform.yml | wc -l | tr -d ' ')" != "$TERRAFORM_IMAGE_REFERENCES" ]
then
echo -e "\033[1;31mError: terraform version in .terraform-version file does not match docker://hashicorp/terraform versions in .github/workflows/continuous-integration-terraform.yml"
exit 1
fi
echo "version=$DOTFILE_VERSION" >> $GITHUB_OUTPUT

- name: Pull Terraform image
run: |
docker pull hashicorp/terraform:${{ steps.get-terraform-version.outputs.version }}

- name: Run a Terraform init
uses: docker://hashicorp/terraform:1.5.3
with:
entrypoint: terraform
args: init
run: |
docker run \
--rm \
-v $(pwd):/terraform \
-w /terraform \
hashicorp/terraform:${{ steps.get-terraform-version.outputs.version }} \
init

- name: Run a Terraform validate
uses: docker://hashicorp/terraform:1.5.3
with:
entrypoint: terraform
args: validate
run: |
docker run \
--rm \
-v $(pwd):/terraform \
-w /terraform \
hashicorp/terraform:${{ steps.get-terraform-version.outputs.version }} \
validate

- name: Run a Terraform format check
uses: docker://hashicorp/terraform:1.5.3
with:
entrypoint: terraform
args: fmt -check=true -diff=true
run: |
docker run \
--rm \
-v $(pwd):/terraform \
-w /terraform \
hashicorp/terraform:${{ steps.get-terraform-version.outputs.version }} \
fmt -check=true -diff=true

terraform-docs-validation:
name: Terraform Docs validation
Expand Down
Loading