Skip to content

consolidating tf scenario 1 workflows into a single cicd pipeline #1

consolidating tf scenario 1 workflows into a single cicd pipeline

consolidating tf scenario 1 workflows into a single cicd pipeline #1

name: 'Scenario 1: Terraform HUB Multi-tenant Secure Baseline'
on:
workflow_dispatch:
inputs:
destroy:
description: 'Destroy resources?'
required: true
type: boolean
default: false
push:
branches:
- main
- refactor/iac-cicd
paths:
- '.github/workflows/scenario1.terraform.yml'
- '.github/workflows/_template.terraform.yml'
- 'scenarios/secure-baseline-multitenant/terraform/hub/**'
- '!scenarios/secure-baseline-multitenant/terraform/hub/**.md'
pull_request:
branches:
- main
paths:
- '.github/workflows/scenario1.terraform.yml'
- '.github/workflows/_template.terraform.yml'
- 'scenarios/secure-baseline-multitenant/terraform/**'
- '!scenarios/secure-baseline-multitenant/terraform/**.md'
permissions:
id-token: write
contents: read
pull-requests: write
env:
modulePath: 'scenarios/secure-baseline-multitenant/terraform/'
terraformVersion: 1.5.2 # must be greater than or equal to 1.2 for OIDC
backendStateKey: 'scenario1.hub.tfstate'
tfvarPath: 'parameters/ase-multitenant.parameters.tfvars'
jobs:
prepare-environment:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@main
outputs:
modulePath: ${{ env.modulePath }}/hub
terraformVersion: ${{ env.terraformVersion }}
backendStateKey: ${{ env.backendStateKey }}
tfvarPath: ${{ env.tfvarPath }}
terraform-deploy-hub:
name: 'Terraform CICD (Hub Multi-tenant Secure Baseline)'
needs:
- prepare-environment
uses: ./.github/workflows/.template.terraform.yml
with:
modulePath: ${{ needs.prepare-environment.outputs.modulePath }}/spoke
terraformVersion: ${{ needs.prepare-environment.outputs.terraformVersion }}
backendStateKey: ${{ needs.prepare-environment.outputs.backendStateKey }}
tfvarPath: ${{ needs.prepare-environment.outputs.tfvarPath }}
# Ensure this value is a boolean
destroy: ${{ github.event.inputs.destroy == 'true' }}
secrets: inherit
terraform-deploy-spoke:
name: 'Terraform CICD (Spoke Multi-tenant Secure Baseline)'
needs:
- prepare-environment
- terraform-deploy-hub
uses: ./.github/workflows/.template.terraform.yml
with:
modulePath: ${{ needs.prepare-environment.outputs.modulePath }}
terraformVersion: ${{ needs.prepare-environment.outputs.terraformVersion }}
backendStateKey: ${{ needs.prepare-environment.outputs.backendStateKey }}
tfvarPath: ${{ needs.prepare-environment.outputs.tfvarPath }}
# Ensure this value is a boolean
destroy: ${{ github.event.inputs.destroy == 'true' }}
secrets: inherit