Skip to content

ci: add terraform apply workflow #12

ci: add terraform apply workflow

ci: add terraform apply workflow #12

Workflow file for this run

name: terraform
on:
push:
branches:
- main
pull_request:
permissions:
id-token: write
contents: read
jobs:
terraform-fmt:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/[email protected]
- name: Set $TERRAFORM_VERSION
working-directory: "./terraform"
run: echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> "$GITHUB_ENV"
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Run terraform fmt
working-directory: "./terraform"
run: terraform fmt -check -recursive
terraform-validate:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set $TERRAFORM_VERSION
working-directory: "./terraform"
run: echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> "$GITHUB_ENV"
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Run terraform init
working-directory: "./terraform"
run: |
terraform init \
-backend-config='bucket=${{ secrets.S3_TFSTATE_BUCKET }}' \
-backend-config='key=${{ secrets.S3_TFSTATE_KEY }}' \
-backend-config='region=${{ secrets.S3_TFSTATE_REGION }}'
- name: Run terraform validate
working-directory: "./terraform"
run: terraform validate
terraform-plan:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set $TERRAFORM_VERSION
working-directory: "./terraform"
run: echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> "$GITHUB_ENV"
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Run terraform init
working-directory: "./terraform"
run: |
terraform init \
-backend-config='bucket=${{ secrets.S3_TFSTATE_BUCKET }}' \
-backend-config='key=${{ secrets.S3_TFSTATE_KEY }}' \
-backend-config='region=${{ secrets.S3_TFSTATE_REGION }}'
- name: Run terraform plan
working-directory: "./terraform"
run: terraform plan
terraform-apply:
runs-on: ubuntu-22.04
needs: terraform-plan
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/[email protected]
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set $TERRAFORM_VERSION
working-directory: "./terraform"
run: echo "TERRAFORM_VERSION=$(cat .terraform-version)" >> "$GITHUB_ENV"
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Run terraform init
working-directory: "./terraform"
run: |
terraform init \
-backend-config='bucket=${{ secrets.S3_TFSTATE_BUCKET }}' \
-backend-config='key=${{ secrets.S3_TFSTATE_KEY }}' \
-backend-config='region=${{ secrets.S3_TFSTATE_REGION }}'
- name: Run terraform apply
working-directory: "./terraform"
run: terraform apply