From fe309c5f7088e48a68358720971cdf0e77e49cc0 Mon Sep 17 00:00:00 2001 From: sid palas Date: Thu, 27 May 2021 15:34:00 -0700 Subject: [PATCH] add staging/production split --- .github/workflows/terraform.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index c82a58d..b6a0cfa 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -4,6 +4,8 @@ on: push: branches: - main + tags: + - v\d+\.\d+\.\d+$ pull_request: jobs: @@ -70,6 +72,20 @@ jobs: if: steps.plan.outcome == 'failure' run: exit 1 - - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - run: terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve \ No newline at end of file + - name: Check tag + id: check-tag + run: | + if [[ ${{ github.event.ref }} =~ ^refs/tags/vd+\.d+\.d+$ ]]; then echo ::set-output name=env::production + elif [[ github.ref == 'refs/heads/main' ]]; then echo ::set-output name=env::staging + else ::set-output name=env::unknown + fi + + - name: Terraform Apply Staging + if: steps.plan.check-tag == 'staging' && github.event_name == 'push' + working-directory: 07-managing-multiple-environments/file-structure/staging + run: terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve + + - name: Terraform Apply Production + if: steps.plan.check-tag == 'production' && github.event_name == 'push' + working-directory: 07-managing-multiple-environments/file-structure/production + run: terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve