This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
Terraform format & plan #487
Workflow file for this run
This file contains 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 format & plan | |
on: | |
pull_request: | |
branches: [master] | |
paths: ['terraform/**'] | |
merge_group: | |
types: [checks_requested] | |
permissions: | |
pull-requests: write | |
env: | |
IMAGE_NAME: 'ghcr.io/${{ github.repository }}' | |
TF_VAR_db_password_dev: ${{ secrets.DB_PASSWORD_DEV }} | |
TF_VAR_db_password_prod: ${{ secrets.DB_PASSWORD_PROD }} | |
TF_VAR_admin_key_dev: ${{ secrets.ADMIN_KEY_DEV }} | |
TF_VAR_admin_key_prod: ${{ secrets.ADMIN_KEY_PROD }} | |
TF_VAR_auth_secret: ${{ secrets.AUTH_SECRET }} | |
TF_VAR_sendgrid_api_key: ${{ secrets.SENDGRID_API_KEY }} | |
TF_VAR_revision_suffix: ${{ github.sha }} | |
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} | |
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} | |
jobs: | |
terraform_format: | |
name: 'Terraform format' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Check format | |
run: | | |
cd terraform | |
terraform fmt -check -recursive | |
terraform_plan: | |
name: 'Terraform plan' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Plan main configuration | |
id: tf_plan | |
run: | | |
cd terraform/main | |
terraform init -lockfile=readonly | |
terraform plan -lock-timeout=15m -no-color | |
- uses: actions/github-script@v7 | |
if: github.event_name == 'pull_request' | |
env: | |
PLAN: "terraform\n${{ steps.tf_plan.outputs.stdout }}" | |
with: | |
github-token: ${{ secrets.REPO_PAT }} | |
script: | | |
const { data: comments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
}) | |
const botComment = comments.find(comment => | |
comment.body.includes('<!-- TERRAFORM PLAN -->') | |
) | |
const output = `<!-- TERRAFORM PLAN --> | |
#### 📖 Terraform plan: \`${{ steps.tf_plan.outcome }}\` | |
<details><summary>Show plan</summary> | |
\`\`\`\n | |
${process.env.PLAN} | |
\`\`\` | |
</details> | |
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`; | |
if (botComment) { | |
github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
body: output | |
}) | |
} else { | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: output | |
}) | |
} |