From 7e9ffedbe6428eab2afa2f13d6dd1e622330fdf7 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 5 Jul 2023 19:46:10 +0100 Subject: [PATCH] Pull out branch name from the environment github ref --- .github/workflows/deploy_terraform.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy_terraform.yml b/.github/workflows/deploy_terraform.yml index b57fb9c2..b06a2468 100644 --- a/.github/workflows/deploy_terraform.yml +++ b/.github/workflows/deploy_terraform.yml @@ -3,7 +3,6 @@ name: CI/CD Pipeline on: push: branches: - - main - dev - prod @@ -49,12 +48,15 @@ jobs: run: cd infrastructure/terraform && terraform init - name: Terraform Plan - run: cd infrastructure/terraform && terraform plan -var-file=${{ github.event.pull_request.base.ref }}.tfvars + run: | + BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e "s/^refs\/heads\///") + cd infrastructure/terraform && terraform plan -var-file=${BRANCH_NAME}.tfvars - name: Terraform Workspace run: | + BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e "s/^refs\/heads\///") cd infrastructure/terraform - terraform workspace select ${{ github.event.pull_request.base.ref }} || terraform workspace new ${{ github.event.pull_request.base.ref }} + terraform workspace select ${BRANCH_NAME} || terraform workspace new ${BRANCH_NAME} - name: Deploy to Dev if: github.ref == 'refs/heads/dev'