Execute Terraform
How to setup and apply Terraform stacks with GitHub Actions.
Last updated
Was this helpful?
How to setup and apply Terraform stacks with GitHub Actions.
Last updated
Was this helpful?
Was this helpful?
name: Single TF Module
on:
workflow_dispatch:
inputs:
cmd:
description: Command to run
type: choice
default: plan
options:
- plan
- apply
- destroy
environment:
description: Environment to deploy to
type: environment
default: dev01
module:
description: Module to run
type: choice
default: tenant
options:
- tenant
- services
- app
workflow_call:
inputs:
cmd:
description: Command to run
type: string
default: plan
environment:
description: Environment to deploy to
type: string
default: dev01
module:
description: Module to run
type: string
default: tenant
secrets:
DUPLO_TOKEN:
description: Duplo Token
required: true
jobs:
module:
name: ${{ inputs.cmd }} ${{ inputs.environment }} ${{ inputs.module }}
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
url: ${{ vars.DUPLO_HOST }}
env:
DUPLO_TOKEN: ${{ secrets.DUPLO_TOKEN }}
DUPLO_HOST: ${{ vars.DUPLO_HOST }}
DUPLO_TENANT: ${{ inputs.environment }}
# add any global tf args here
TF_CLI_ARGS_apply: -parallelism=1
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Duplo and AWS Setup
uses: duplocloud/actions@main
with:
admin: true
- name: Terraform Setup
uses: duplocloud/actions/setup-terraform@main
- name: TF Validate Module
uses: duplocloud/actions/terraform-module@main
with:
module: modules/${{ inputs.module }}
test: false
- name: TF Execute Module
uses: duplocloud/actions/terraform-exec@main
with:
module: modules/${{ inputs.module }}
workspace: ${{ inputs.environment }}
command: ${{ inputs.cmd }}
name: Apply My Stack
on:
workflow_dispatch:
inputs:
environment:
description: Environment to deploy to
type: environment
default: dev01
jobs:
tenant:
# Name is the same b/c it nests the jobs correctly in the ui
name: My Stack
# run the single module job
uses: ./.github/workflows/module.tf
secrets: inherit
with:
cmd: apply
environment: ${{ inputs.environment }}
module: tenant
services:
name: My Stack
uses: ./.github/workflows/module.tf
secrets: inherit
needs: tenant
with:
cmd: apply
environment: ${{ inputs.environment }}
module: services
app:
name: My Stack
uses: ./.github/workflows/module.tf
secrets: inherit
needs: services
with:
cmd: apply
environment: ${{ inputs.environment }}
module: app