From 5e443132c480b6b84eba97bb4fa714479a6eadae Mon Sep 17 00:00:00 2001 From: Andrew Pearce Date: Mon, 25 Sep 2023 10:33:06 +0100 Subject: [PATCH] get and set terraform version using version.tf (#726) --- .../dispatch_change_dns_target_region.yml | 14 +++++++++++++- ...ispatch_manage_public_access_ur_environment.yml | 14 +++++++++++++- .github/workflows/terraform_account_job.yml | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dispatch_change_dns_target_region.yml b/.github/workflows/dispatch_change_dns_target_region.yml index ed66487208..b1be79f096 100644 --- a/.github/workflows/dispatch_change_dns_target_region.yml +++ b/.github/workflows/dispatch_change_dns_target_region.yml @@ -52,9 +52,21 @@ jobs: run: | aws ssm put-parameter --name "/modernising-lpa/dns-target-region/${{ github.event.inputs.environment }}" --type "String" --value "${{ github.event.inputs.region }}" --overwrite + - name: Parse terraform version + id: tf_version_setup + working-directory: ./terraform/environment + run: | + if [ -f ./versions.tf ]; then + terraform_version=$(cat ./versions.tf | ../../scripts/terraform-version.sh) + echo "- Terraform version: [${terraform_version}]" >> $GITHUB_STEP_SUMMARY + echo "TERRAFORM_VERSION=${terraform_version}" >> $GITHUB_OUTPUT + fi + - name: "Terraform version [${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }}]" + run: echo "terraform version [${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }}]" + working-directory: ./terraform/environment - uses: hashicorp/setup-terraform@v2 with: - terraform_version: 1.5.2 + terraform_version: ${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }} terraform_wrapper: false - name: Configure AWS Credentials For Terraform uses: aws-actions/configure-aws-credentials@v4 diff --git a/.github/workflows/dispatch_manage_public_access_ur_environment.yml b/.github/workflows/dispatch_manage_public_access_ur_environment.yml index 607527eb15..2cc3aae92f 100644 --- a/.github/workflows/dispatch_manage_public_access_ur_environment.yml +++ b/.github/workflows/dispatch_manage_public_access_ur_environment.yml @@ -31,9 +31,21 @@ jobs: steps: - uses: actions/checkout@v4 - uses: unfor19/install-aws-cli-action@v1 + - name: Parse terraform version + id: tf_version_setup + working-directory: ./terraform/environment + run: | + if [ -f ./versions.tf ]; then + terraform_version=$(cat ./versions.tf | ../../scripts/terraform-version.sh) + echo "- Terraform version: [${terraform_version}]" >> $GITHUB_STEP_SUMMARY + echo "TERRAFORM_VERSION=${terraform_version}" >> $GITHUB_OUTPUT + fi + - name: "Terraform version [${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }}]" + run: echo "terraform version [${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }}]" + working-directory: ./terraform/environment - uses: hashicorp/setup-terraform@v2 with: - terraform_version: 1.5.2 + terraform_version: ${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }} terraform_wrapper: false - name: Configure AWS Credentials For Terraform uses: aws-actions/configure-aws-credentials@v4 diff --git a/.github/workflows/terraform_account_job.yml b/.github/workflows/terraform_account_job.yml index 2c25541026..2206a2fb32 100644 --- a/.github/workflows/terraform_account_job.yml +++ b/.github/workflows/terraform_account_job.yml @@ -26,7 +26,7 @@ jobs: - uses: unfor19/install-aws-cli-action@v1 - name: Parse terraform version id: tf_version_setup - working-directory: ./terraform/environment + working-directory: ./terraform/account run: | if [ -f ./versions.tf ]; then terraform_version=$(cat ./versions.tf | ../../scripts/terraform-version.sh) @@ -35,7 +35,7 @@ jobs: fi - name: "Terraform version [${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }}]" run: echo "terraform version [${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }}]" - working-directory: ./terraform/environment + working-directory: ./terraform/account - uses: hashicorp/setup-terraform@v2 with: terraform_version: ${{ steps.tf_version_setup.outputs.TERRAFORM_VERSION }}