Skip to content

Terraform CI-CD

Terraform CI-CD #11

name: 'Terraform CI-CD'
on:
workflow_dispatch:
push:
branches:
- main
env:
TERRAFORM_VERSION: 1.7.5
permissions:
id-token: write
contents: read
jobs:
terraformValidation:
name: 'Validate configurations'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Terraform Init and Validate
run: |
terraform init
terraform validate
terraformExecution:
name: 'Apply configurations'
needs: terraformValidation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Terraform Init, Plan and Apply
run: |
terraform init
terraform plan
terraform apply -auto-approve