Skip to content

Terraform flow

Terraform flow #21

name: Terraform flow
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Which environment you wish to use
options:
- integration
- production
resource:
type: choice
description: Which resource you wish to create
options:
- key-vault
- storage-account
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: self-hosted
environment: ${{ inputs.environment }}
env:
WORK_DIR: ${{ inputs.environment }}/${{ inputs.resource }}/
ARM_SUBSCRIPTION_ID: ${{ inputs.environment == 'integration' && secrets.SUBSCRIPTION_ID || secrets.SUBSCRIPTION_ID_PROD}}
ARM_TENANT_ID: ${{ secrets.TENANT_ID }}
ARM_CLIENT_ID: ${{ inputs.environment == 'integration' && secrets.CLIENT_ID || secrets.CLIENT_ID_PROD}}
ARM_CLIENT_SECRET: ${{ inputs.environment == 'integration' && secrets.CLIENT_SECRET || secrets.CLIENT_SECRET_PROD}}
steps:
- uses: actions/checkout@v3
- name: Log in with Azure
uses: azure/login@v1
with:
creds: ${{ inputs.environment == 'integration' && secrets.INTEGRATION_CREDS || secrets.PRODUCTION_CREDS}}
- name: run terraform init
working-directory: ${{ env.WORK_DIR }}
run: terraform init
- name: run terraform plan
working-directory: ${{ env.WORK_DIR }}
run: terraform plan -out=../../../plan$GITHUB_RUN_ID.json
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: Planning$GITHUB_RUN_ID
path: plan$GITHUB_RUN_ID.json
retention-days: 1