Rename GitHub workflow (#10) #19
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" | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
permissions: | |
id-token: write | |
contents: read | |
pull-requests: write | |
env: | |
CI_ENVIRONMENT_NAME: prod | |
TF_LOG: INFO | |
TF_VAR_bucket_name: ${{ vars.BUCKET_NAME }} | |
jobs: | |
terraform: | |
name: "Terraform" | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: terraform/ | |
steps: | |
- name: Git Checkout | |
uses: actions/checkout@v4 | |
- name: Configure AWS credentials from AWS account | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE }} | |
aws-region: "eu-west-3" | |
role-session-name: ${{ github.event.repository.name }} | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.7.0 | |
- name: Terraform fmt | |
id: fmt | |
run: terraform fmt -check | |
continue-on-error: true | |
- name: Terraform Init | |
id: init | |
run: CI=true make init | |
- name: Terraform Validate | |
id: validate | |
run: CI=true make validate | |
- name: Terraform Plan | |
id: plan | |
run: CI=true make plan-save-output | |
continue-on-error: true | |
- uses: actions/github-script@v7 | |
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 }}\` | |
<details><summary>Validation Output</summary> | |
\`\`\`\n | |
${{ steps.validate.outputs.stdout }} | |
\`\`\` | |
</details> | |
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | |
<details><summary>Show Plan</summary> | |
\`\`\`\n | |
${process.env.PLAN} | |
\`\`\` | |
</details> | |
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | |
github.rest.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 | |
id: apply | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
run: CI=true make apply-from-plan |