Skip to content

Merge pull request #921 from maztah1/docs/wave-contributor-guide #1

Merge pull request #921 from maztah1/docs/wave-contributor-guide

Merge pull request #921 from maztah1/docs/wave-contributor-guide #1

Workflow file for this run

name: Infrastructure CI
on:
push:
branches: [main]
paths: ['infra/**', '.github/workflows/infra.yml']
pull_request:
paths: ['infra/**', '.github/workflows/infra.yml']
env:
TF_VERSION: "1.8.5"
AWS_REGION: "us-east-1"
jobs:
validate:
name: Validate (${{ matrix.env }})
runs-on: ubuntu-latest
strategy:
matrix:
env: [staging, production]
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: fmt check
run: terraform fmt -check -recursive -diff
working-directory: infra/envs/${{ matrix.env }}
- name: init (no backend)
run: terraform init -backend=false -input=false
working-directory: infra/envs/${{ matrix.env }}
- name: validate
run: terraform validate
working-directory: infra/envs/${{ matrix.env }}
plan-staging:
name: Plan (staging)
needs: validate
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
environment: staging
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: init
run: terraform init -input=false
working-directory: infra/envs/staging
- name: plan
id: plan
run: terraform plan -no-color -input=false -out=tfplan 2>&1 | tee plan.txt
working-directory: infra/envs/staging
env:
TF_VAR_acm_certificate_arn: ${{ vars.STAGING_ACM_CERT_ARN }}
- name: Comment plan on PR
uses: actions/github-script@v7
if: always()
with:
script: |
const fs = require('fs');
const plan = fs.readFileSync('infra/envs/staging/plan.txt', 'utf8');
const truncated = plan.length > 60000 ? plan.slice(0, 60000) + '\n...(truncated)' : plan;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## Terraform Plan — staging\n\`\`\`hcl\n${truncated}\n\`\`\``
});
apply-staging:
name: Apply (staging)
needs: validate
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment: staging
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: init
run: terraform init -input=false
working-directory: infra/envs/staging
- name: apply
run: terraform apply -auto-approve -input=false
working-directory: infra/envs/staging
env:
TF_VAR_acm_certificate_arn: ${{ vars.STAGING_ACM_CERT_ARN }}
apply-production:
name: Apply (production)
needs: apply-staging
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment: production # requires manual approval via GitHub environment
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: init
run: terraform init -input=false
working-directory: infra/envs/production
- name: apply
run: terraform apply -auto-approve -input=false
working-directory: infra/envs/production
env:
TF_VAR_acm_certificate_arn: ${{ secrets.PROD_ACM_CERT_ARN }}