-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathazure-pipelines.yml
72 lines (64 loc) · 2.21 KB
/
azure-pipelines.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
64
65
66
67
68
69
70
71
72
# trigger:
# - master
pool:
vmImage: 'ubuntu-latest'
variables:
subscription: Visual Studio Enterprise(17b12858-3960-4e6f-a663-a06fdae23428)
resourceGroup: resourcegroup-tfstate
storageAccount: terraformtfstateskip
container: tfstate
tfstateFile: terraform.tfstate
anyTfChanges: false
steps:
- task: TerraformInstaller@0
displayName: install Terraform v0.12.28
inputs:
terraformVersion: '0.12.28'
- task: TerraformTaskV1@0
displayName: terraform init
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/skip-step'
backendServiceArm: '$(subscription)'
backendAzureRmResourceGroupName: '$(resourceGroup)'
backendAzureRmStorageAccountName: '$(storageAccount)'
backendAzureRmContainerName: '$(container)'
backendAzureRmKey: '$(tfstateFile)'
- task: TerraformTaskV1@0
displayName: terraform plan -out=tfplan
inputs:
provider: 'azurerm'
command: 'plan'
workingDirectory: '$(System.DefaultWorkingDirectory)/skip-step'
commandOptions: '-out=tfplan'
# commandOptions: '-detailed-exitcode -out=tfplan'
environmentServiceNameAzureRM: '$(subscription)'
- task: PowerShell@2
displayName: detect any terraform change
inputs:
workingDirectory: '$(System.DefaultWorkingDirectory)/skip-step'
targetType: 'inline'
script: |
# Write-Host "LASTEXITCODE : $LASTEXITCODE"
$plan = $(terraform show -json tfplan | ConvertFrom-Json)
$actions = $plan.resource_changes.change.actions
Write-Host "Terraform actions : $actions"
if (($actions -contains 'create') -or ($actions -contains 'delete') -or ($actions -contains 'update'))
{
Write-Host "Terraform will perform the following actions : $actions"
Write-Host "##vso[task.setvariable variable=anyTfChanges;]true"
}
else
{
Write-Host "There is no change detected in Terraform tfplan file"
}
- task: TerraformTaskV1@0
displayName: terraform apply tfplan
condition: eq(variables.anyTfChanges, true)
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/skip-step'
commandOptions: 'tfplan'
environmentServiceNameAzureRM: '$(subscription)'