feat: Improve workflow structure #35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Terraform CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| plan: | |
| name: Terraform Plan | |
| runs-on: ubuntu-latest | |
| outputs: | |
| plan-exit-code: ${{ steps.plan.outcome }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Authenticate with GCP | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_CREDENTIALS }} | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: latest | |
| - name: Initialize Terraform | |
| working-directory: ./terraform | |
| run: terraform init | |
| - name: Terraform Plan | |
| id: plan | |
| working-directory: ./terraform | |
| run: terraform plan -out=tfplan | |
| continue-on-error: false | |
| - name: Upload Plan Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: tfplan | |
| path: ./terraform/tfplan | |
| apply: | |
| name: Terraform Apply | |
| needs: plan | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Authenticate with GCP | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_CREDENTIALS }} | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: latest | |
| - name: Download Plan Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: tfplan | |
| path: ./terraform | |
| - name: Initialize Terraform | |
| working-directory: ./terraform | |
| run: terraform init | |
| - name: Apply Terraform Changes | |
| working-directory: ./terraform | |
| run: terraform apply -auto-approve tfplan |