From 804743d2dff5b07ee64c4d3fd0ce41d61cdf9b61 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 18 Feb 2025 21:20:03 -0500 Subject: [PATCH] feat: added deploy option when on the main branch --- .github/workflows/check.yml | 42 --------------------------- .github/workflows/deploy.yml | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml deleted file mode 100644 index a3bd629..0000000 --- a/.github/workflows/check.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Quality Assurance - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - terraform: - name: Ensure Sound Infrastructure - runs-on: ubuntu-latest - - steps: - - name: Checkout to Repository - uses: actions/checkout@v2 - - - name: Set-up Terraform - uses: hashicorp/setup-terraform@v2 - - - name: Format Terraform - run: | - cd terraform - terraform fmt -check - - - name: Initialize Terraform Back-end - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - run: | - cd terraform - terraform init - - - name: Terraform Plan - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - run: | - cd terraform - terraform plan -out=tfplan -no-color \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1721b56 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,56 @@ +name: Build and Deploy Architecture + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + terraform: + name: Deploy Infrastructure + runs-on: ubuntu-latest + + steps: + - name: Checkout to Repository + uses: actions/checkout@v2 + + - name: Set-up Terraform + uses: hashicorp/setup-terraform@v2 + + - name: Format Terraform + run: terraform fmt -check + working-directory: ./terraform + + - name: Initialize Terraform Back-end + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: terraform init + working-directory: ./terraform + + - name: Terraform Plan + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: terraform plan -out=tfplan -no-color + working-directory: ./terraform + + - name: Check if there are changes + id: check_changes + run: | + if [ -n "$(terraform show -no-color tfplan | grep -E 'No changes.')" ]; then + echo "No changes detected." + echo "::set-output name=changes::false" + else + echo "Changes detected." + echo "::set-output name=changes::true" + fi + working-directory: ./terraform + + - name: Terraform Apply + if: ${{ (steps.check_changes.outputs.changes == 'true') && (github.ref == 'refs/heads/master') }} + run: terraform apply -auto-approve tfplan + working-directory: ./terraform \ No newline at end of file