-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (50 loc) · 1.72 KB
/
azure-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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