Skip to content

Update README.md

Update README.md #4

Workflow file for this run

name: "Terraform"
on:
push:
branches:
- main
- dev
pull_request:
jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./terraform
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Configuration for dev branch
if: ${{ github.ref == 'refs/heads/dev'}}
# Side note, I can run any Linux command here, not just 'echo'
run: |
echo "TF_VAR_SLACK_SIGNING_SECRET=${{ secrets.DEV_TF_VAR_SLACK_SIGNING_SECRET }}" >> $GITHUB_ENV
echo "TF_VAR_SLACK_BOT_TOKEN=${{ secrets.DEV_TF_VAR_SLACK_BOT_TOKEN }}" >> $GITHUB_ENV
echo "TF_VAR_GOOGLE_SERVICE_BASE64_FILE_CONTENT=${{ secrets.DEV_TF_VAR_GOOGLE_SERVICE_BASE64_FILE_CONTENT }}" >> $GITHUB_ENV
echo "TF_VAR_DB_SPREADSHEET_ID=${{ secrets.DEV_TF_VAR_DB_SPREADSHEET_ID }}" >> $GITHUB_ENV
echo "TF_VAR_REGION=${{ secrets.DEV_AWS_REGION }}" >> $GITHUB_ENV
echo "AWS_REGION=${{ secrets.DEV_AWS_REGION }}" >> $GITHUB_ENV
echo "TF_VAR_S3_BACKEND_BUCKET=${{ secrets.DEV_TF_VAR_S3_BACKEND_BUCKET }}" >> $GITHUB_ENV
echo "TF_VAR_BUILD_IN_DOCKER=${{ secrets.DEV_TF_VAR_BUILD_IN_DOCKER }}" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY_ID=${{ secrets.DEV_AWS_ACCESS_KEY_ID }}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV
- name: Configuration for main branch
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'pull_request' }}
run: |
echo "TF_VAR_SLACK_SIGNING_SECRET=${{ secrets.TF_VAR_SLACK_SIGNING_SECRET }}" >> $GITHUB_ENV
echo "TF_VAR_SLACK_BOT_TOKEN=${{ secrets.TF_VAR_SLACK_BOT_TOKEN }}" >> $GITHUB_ENV
echo "TF_VAR_GOOGLE_SERVICE_BASE64_FILE_CONTENT=${{ secrets.TF_VAR_GOOGLE_SERVICE_BASE64_FILE_CONTENT }}" >> $GITHUB_ENV
echo "TF_VAR_DB_SPREADSHEET_ID=${{ secrets.TF_VAR_DB_SPREADSHEET_ID }}" >> $GITHUB_ENV
echo "TF_VAR_REGION=${{ secrets.AWS_REGION }}" >> $GITHUB_ENV
echo "AWS_REGION=${{ secrets.AWS_REGION }}" >> $GITHUB_ENV
echo "TF_VAR_S3_BACKEND_BUCKET=${{ secrets.TF_VAR_S3_BACKEND_BUCKET }}" >> $GITHUB_ENV
echo "TF_VAR_BUILD_IN_DOCKER=${{ secrets.TF_VAR_BUILD_IN_DOCKER }}" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
- name: Terraform Init
id: init
run: terraform init -backend-config="bucket="${TF_VAR_S3_BACKEND_BUCKET}"" -backend-config="region="${TF_VAR_REGION}""
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color
continue-on-error: true
- uses: actions/[email protected]
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push'
run: terraform apply -auto-approve