Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Terraform
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
inputs:
environment:
description: Environment to run
required: true
type: choice
default: dev
options: [dev, prod]
operation:
description: Plan only, or plan and apply
required: true
type: choice
default: plan
options: [plan, apply]
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: 1.16.5
terraform_wrapper: false
- run: bash scripts/check.sh
- run: bash scripts/test.sh
deploy:
name: Terraform (${{ matrix.target }})
needs: validate
# Fork code never receives an OIDC session or access to state. Its validate job still runs.
if: >-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
(github.event_name == 'workflow_dispatch' && (inputs.operation == 'plan' || github.ref == 'refs/heads/main'))
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: ${{ github.event_name == 'workflow_dispatch' && fromJSON(format('["{0}"]', inputs.environment)) || fromJSON('["dev", "prod"]') }}
environment: ${{ (github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.operation == 'plan')) && format('{0}-plan', matrix.target) || matrix.target }}
permissions:
contents: read
id-token: write
pull-requests: write
concurrency:
group: terraform-${{ matrix.target }}
cancel-in-progress: false
env:
TF_IN_AUTOMATION: 'true'
TF_INPUT: 'false'
TARGET: ${{ matrix.target }}
EVENT: ${{ github.event_name }}
OPERATION: ${{ github.event_name == 'pull_request' && 'plan' || inputs.operation }}
AWS_REGION: ${{ vars.AWS_REGION }}
STATE_BUCKET: ${{ vars.TF_STATE_BUCKET }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: 1.16.5
terraform_wrapper: false
- uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
role-session-name: terraform-${{ github.run_id }}
role-duration-seconds: 3600
allowed-account-ids: ${{ vars.AWS_ACCOUNT_ID }}
- name: Plan or apply platform, then monitoring
shell: bash
env:
PLAN_REPORT: ${{ runner.temp }}/terraform-plan-${{ matrix.target }}.md
run: bash scripts/deploy.sh
- name: Update PR plan comment
if: always() && github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PLAN_JOB_STATUS: ${{ job.status }}
PLAN_REPORT: ${{ runner.temp }}/terraform-plan-${{ matrix.target }}.md
run: bash scripts/comment-plan.sh
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
**/.terraform/*
*.tfstate
*.tfstate.*
*.tfplan
crash.log
crash.*.log
**/backend.hcl
**/backend.bootstrap.hcl
bootstrap/terraform.tfvars
*.auto.tfvars
*.auto.tfvars.json
*.tfvars.local
*.tfvars.local.json
.terraformrc
terraform.rc
bootstrap/backend.tf
audit/
__pycache__/
*.pyc
1 change: 1 addition & 0 deletions .terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.16.5
Loading
Loading