|
| 1 | +--- |
| 2 | +on: |
| 3 | + push: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +env: |
| 7 | + AWS_REGION: ${{ vars.AWS_REGION }} |
| 8 | + AWS_ENDPOINT_URL_S3: ${{ vars.AWS_ENDPOINT_URL_S3 }} |
| 9 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 10 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 11 | + GITHUB_OWNER: ${{ vars.OWNER }} |
| 12 | + GITHUB_APP_ID: ${{ vars.APP_ID }} |
| 13 | + GITHUB_APP_INSTALLATION_ID: ${{ vars.APP_INSTALLATION_ID }} |
| 14 | + GITHUB_APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + terraform: |
| 18 | + name: "Terraform" |
| 19 | + runs-on: ubuntu-latest |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + shell: bash |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout the repository to the runner |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Setup Terraform with specified version on the runner |
| 29 | + uses: hashicorp/setup-terraform@v3 |
| 30 | + with: |
| 31 | + terraform_version: 1.11.0 |
| 32 | + |
| 33 | + - name: Terraform init |
| 34 | + id: init |
| 35 | + run: terraform init |
| 36 | + |
| 37 | + - name: Terraform plan |
| 38 | + id: plan |
| 39 | + if: github.event_name == 'pull_request' |
| 40 | + run: terraform plan -no-color -input=false |
| 41 | + continue-on-error: true |
| 42 | + |
| 43 | + - uses: actions/github-script@v7 |
| 44 | + if: github.event_name == 'pull_request' |
| 45 | + env: |
| 46 | + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" |
| 47 | + with: |
| 48 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + script: | |
| 50 | + const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 51 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 52 | +
|
| 53 | + <details><summary>Show Plan</summary> |
| 54 | +
|
| 55 | + \`\`\`\n |
| 56 | + ${process.env.PLAN} |
| 57 | + \`\`\` |
| 58 | +
|
| 59 | + </details> |
| 60 | + *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 61 | +
|
| 62 | + github.rest.issues.createComment({ |
| 63 | + issue_number: context.issue.number, |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + body: output |
| 67 | + }) |
| 68 | +
|
| 69 | + - name: Terraform Plan Status |
| 70 | + if: steps.plan.outcome == 'failure' |
| 71 | + run: exit 1 |
| 72 | + |
| 73 | + - name: Terraform Apply |
| 74 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 75 | + run: terraform apply -auto-approve -input=false |
0 commit comments