Skip to content

Terraform GitHub Actions #2

Terraform GitHub Actions

Terraform GitHub Actions #2

Workflow file for this run

name: 'Terraform GitHub Actions'
on:
push:
branches:
- master
workflow_dispatch:
inputs:
confirm:
description: 'Type "yes" to confirm destroy action'
required: true
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
terraform_apply:
name: 'Terraform Apply'
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.8.2
- name: Terraform Init
run: terraform init
- name: Terraform Apply
run: terraform apply -auto-approve
env:
TF_VAR_db_password: ${{ secrets.DB_PASSWORD }}
terraform_destroy:
name: 'Terraform Destroy'
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.event.inputs.confirm == 'yes'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.8.2
- name: Terraform Init
run: terraform init
- name: Terraform Destroy
run: terraform destroy -auto-approve