Skip to content

Infrastructure using Terraform #48

Infrastructure using Terraform

Infrastructure using Terraform #48

name: 'Infrastructure using Terraform'
on:
workflow_run:
workflows: ["Build Docker image"]
types: [completed]
branches:
- main
permissions:
contents: read
jobs:
terraform:
env:
GOOGLE_CREDENTIALS: ${{ github.workspace }}/infra/main/infra_service_account.json
name: "Terraform"
runs-on: ubuntu-latest
environment: production
defaults:
run:
working-directory: ./infra/main
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.3.2
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
id: fmt
run: terraform fmt -check
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
id: init
run: |
terraform init
# Linting
- name: Lint Terraform
uses: actionshub/terraform-lint@main
# Validate
- name: Terraform Validate
id: validate
run: terraform validate -no-color
# Generates an execution plan for Terraform
- name: Terraform Plan
run: terraform plan -no-color -out=./terraform_plan
# Apply the changes
- name: Terraform Apply
id: apply
run: terraform apply -auto-approve ./terraform_plan