Test live coding 6 #1
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: VPC Demo - Terraform Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'vpc-demo/**' | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'vpc-demo/**' | |
| workflow_dispatch: | |
| permissions: | |
| id-token: write | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| terraform: | |
| name: Terraform | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: vpc-demo | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-role | |
| aws-region: eu-west-3 | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.7.0 | |
| - name: Terraform Init | |
| run: terraform init | |
| - name: Terraform Format | |
| run: terraform fmt -check | |
| continue-on-error: true | |
| - name: Terraform Validate | |
| run: terraform validate | |
| - name: Terraform Plan | |
| id: plan | |
| run: terraform plan -no-color -var="aws_profile=" -out=tfplan | |
| continue-on-error: true | |
| - name: Comment PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | |
| <details><summary>Show Plan</summary> | |
| \`\`\`terraform | |
| ${{ steps.plan.outputs.stdout }} | |
| \`\`\` | |
| </details>`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: output | |
| }) | |
| - name: Terraform Apply | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: terraform apply -auto-approve -var="aws_profile=" tfplan |