|
| 1 | +name: deploy.webhook |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + workflow_dispatch: |
| 8 | +env: |
| 9 | + AWS_REGION: us-west-2 |
| 10 | +jobs: |
| 11 | + terraform: |
| 12 | + name: Terraform |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v2 |
| 17 | + - name: Setup Terraform |
| 18 | + uses: hashicorp/setup-terraform@v1 |
| 19 | + - name: Configure AWS Credentials |
| 20 | + uses: aws-actions/configure-aws-credentials@v1 |
| 21 | + with: |
| 22 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 23 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 24 | + aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} |
| 25 | + aws-region: ${{ env.AWS_REGION }} |
| 26 | + - name: Add profile credentials to ~/.aws/credentials |
| 27 | + run: | |
| 28 | + aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} --profile default |
| 29 | + aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile default |
| 30 | + aws configure set aws_region ${{ env.AWS_REGION }} --profile default |
| 31 | + - name: Terraform Format |
| 32 | + id: fmt |
| 33 | + run: terraform fmt -check -diff |
| 34 | + - name: Terraform Init |
| 35 | + id: init |
| 36 | + run: terraform init |
| 37 | + - name: Terraform Plan |
| 38 | + id: plan |
| 39 | + if: github.event_name == 'pull_request' |
| 40 | + run: terraform plan -input=false -no-color |
| 41 | + continue-on-error: true |
| 42 | + env: |
| 43 | + TF_VAR_indent_webhook_secret: ${{ secrets.INDENT_WEBHOOK_SECRET }} |
| 44 | + TF_VAR_default_user_pw: ${{ secrets.DEFAULT_USER_PW }} |
| 45 | + - uses: actions/github-script@0.9.0 |
| 46 | + if: github.event_name == 'pull_request' |
| 47 | + env: |
| 48 | + PLAN: |- |
| 49 | + terraform |
| 50 | + ${{ steps.plan.outputs.stdout }} |
| 51 | + with: |
| 52 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + script: | |
| 54 | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` |
| 55 | + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 56 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 57 | + <details><summary>Show Plan</summary> |
| 58 | + \`\`\`${process.env.PLAN}\`\`\` |
| 59 | + </details> |
| 60 | + *Actor: @${{ github.actor }}, Event: \`${{ github.event_name }}\`*`; |
| 61 | + github.issues.createComment({ |
| 62 | + issue_number: context.issue.number, |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + body: output |
| 66 | + }) |
| 67 | + - name: Terraform Plan Status |
| 68 | + if: steps.plan.outcome == 'failure' |
| 69 | + run: exit 1 |
| 70 | + - name: Terraform Apply |
| 71 | + if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') |
| 72 | + run: terraform apply -input=false -auto-approve |
| 73 | + env: |
| 74 | + TF_VAR_indent_webhook_secret: ${{ secrets.INDENT_WEBHOOK_SECRET }} |
| 75 | + TF_VAR_default_user_pw: ${{ secrets.DEFAULT_USER_PW }} |
| 76 | + - name: Terraform Output |
| 77 | + if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') |
| 78 | + run: terraform output |
| 79 | + env: |
| 80 | + TF_VAR_indent_webhook_secret: ${{ secrets.INDENT_WEBHOOK_SECRET }} |
| 81 | + TF_VAR_example_api_key: ${{ secrets.EXAMPLE_API_KEY}} |
0 commit comments