final commit #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Azure | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
deploy: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 0.15.5 | |
- name: Install Azure CLI | |
run: | | |
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi | |
Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet' | |
- name: Check Azure CLI version | |
run: az --version | |
- name: Log in to Azure | |
run: | | |
az login --service-principal -u $env:AZURE_CLIENT_ID -p $env:AZURE_CLIENT_SECRET --tenant $env:AZURE_TENANT_ID | |
env: | |
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} | |
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
- name: Show Azure Account | |
run: az account show | |
- name: Terraform Init | |
run: terraform init | |
- name: Terraform Plan | |
run: terraform plan -out=tfplan | |
- name: Terraform Apply | |
run: terraform apply -auto-approve tfplan | |
- name: Clean up Terraform files | |
run: | | |
# Remove .terraform directory if it exists | |
if (Test-Path .\.terraform) { | |
Remove-Item -Recurse -Force .\.terraform | |
} | |
# Remove tfplan file if it exists | |
if (Test-Path .\tfplan) { | |
Remove-Item -Force .\tfplan | |
} | |
continue-on-error: true # Continue with the workflow even if cleanup fails | |
- name: Destroy Terraform configuration (if deploy was successful) | |
if: ${{ steps.deploy.conclusion == 'success' }} | |
run: terraform destroy -auto-approve |