Skip to content

edited gh action

edited gh action #16

name: 'Terraform'
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
id-token: write
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
strategy:
# max-parallel: 10
matrix:
# directory: [001_vnet_subnets_tf, 002_vm_bastion, 003_vm_bastion_nsg, 004_vnet_peering_tf, 005_vm_linux_win_bastion, 006_route_table]
directory: [004_vnet_peering_tf, 003_vm_bastion_nsg, 200_hub_spoke_firewall, 300_load_balancer_vm, 301_load_balancer_vmss, 302_load_balancer_internal_vmss_natgateway, 400_private_dns_zone, 410_private_endpoint_mssql, 420_private_endpoint_pls]
# node: [14, 16]
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
# Login to Azure using OIDC
- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Azure CLI script
uses: azure/CLI@v1
with:
azcliversion: latest
inlineScript: |
az account show
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform -chdir=${{ matrix.directory }} init
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
run: terraform fmt -check
working-directory: ${{ matrix.directory }}
continue-on-error: true
# Generates an execution plan for Terraform
- name: Terraform Plan
run: terraform plan -out tfplan
working-directory: ${{ matrix.directory }}
# On push to "main", build or change infrastructure according to Terraform configuration files
# Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
- name: Terraform Apply
run: terraform apply tfplan
working-directory: ${{ matrix.directory }}
# if: github.ref == 'refs/heads/"main"' && github.event_name == 'push'
# Terraform Destroy
- name: Terraform Destroy
run: terraform destroy -auto-approve -input=false
working-directory: ${{ matrix.directory }}