From b0ec428757f8a235f068e2fb413314dc5289c6d2 Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Mon, 9 Oct 2023 16:09:28 +0100 Subject: [PATCH] Get Terraform version from dotfile in workflow * Gets the terraform version from the dotfile and sets it as a variable to be used throughout the workflow. Prevents needing to update all the docker image references when the terraform version is updated. --- .../continuous-integration-terraform.yml | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/.github/workflows/continuous-integration-terraform.yml b/.github/workflows/continuous-integration-terraform.yml index 6aef6e4..f8cfec2 100644 --- a/.github/workflows/continuous-integration-terraform.yml +++ b/.github/workflows/continuous-integration-terraform.yml @@ -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