Run terraform scripts with github actions
name : ' provision resources'
on :
push :
branches :
- main
workflow_dispatch :
env :
ARM_CLIENT_ID : ${{ secrets.AZURE_AD_CLIENT_ID }}
ARM_CLIENT_SECRET : ${{ secrets.AZURE_AD_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID : ${{ secrets.AZURE_AD_TENANT_ID }}
jobs :
terraform :
name : ' Terraform'
defaults :
run :
working-directory : " ./terraform"
runs-on : ubuntu-latest
environment : production
steps :
- name : Checkout
uses : actions/checkout@v2
- name : Setup Terraform
uses : hashicorp/setup-terraform@v1
- name : Terraform Format
id : fmt
run : terraform fmt -check
- name : Terraform Init
id : init
run : terraform init
- name : Terraform Plan
id : plan
run : terraform plan -no-color
continue-on-error : true
- name : Terraform Plan Status
if : steps.plan.outcome == 'failure'
run : exit 1
- name : Terraform Apply
if : github.ref == 'refs/heads/main' && github.event_name == 'push'
run : terraform apply -auto-approve