-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines-backend.yml
95 lines (91 loc) · 2.97 KB
/
azure-pipelines-backend.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# pool:
# name: Default
# Demands:
# - agent.name -equals sfq_win
pool:
vmImage: ubuntu-latest
trigger:
branches:
include:
- main
variables:
- group: Terraform_Variable
resources:
repositories:
- repository: githubrepo
type: github
name: safiqkhan/Terraform_Azure
endpoint: github_safiqkhan
ref: master
trigger:
- master
parameters:
- name: execlevel
displayName: Execution Level
type: string
default: plan
values:
- plan
- apply
stages:
- stage: tfvalidate
condition: eq ('${{parameters.execlevel}}' , 'plan')
jobs:
- job: validate
continueOnError: false
steps:
- checkout: githubrepo
- task: TerraformInstaller@0
displayName: 'Install Terraform'
inputs:
terraformVersion: 'latest'
- task: TerraformCLI@0
displayName: 'Initialise Terraform'
inputs:
command: 'init'
workingDirectory: '$(Build.SourcesDirectory)/backend'
- task: TerraformCLI@0
displayName: 'Validate Terraform'
inputs:
command: 'validate'
workingDirectory: '$(Build.SourcesDirectory)/backend'
- task: TerraformCLI@0
displayName: 'Plan Terraform'
inputs:
command: 'plan'
environmentServiceName: 'Free_Trial'
workingDirectory: '$(Build.SourcesDirectory)/backend'
commandOptions: '-var resource_group_name=$(storage_rg_name) -var storage_account_name=$(storage_account_name)'
publishPlanResults: 'Terraform_plan'
# - task: CmdLine@2
# inputs:
# script: 'cp -r !(folder_to_skip) $(Build.ArtifactStagingDirectory)'
# workingDirectory: '$(Build.SourcesDirectory)'
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: '**azure-pipelines-backend.yml'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'Terraform'
- stage: tfdeploy
condition: eq ('${{parameters.execlevel}}' , 'apply')
dependsOn: tfvalidate
jobs:
- job: apply
steps:
- checkout: githubrepo
- task: TerraformCLI@0
displayName: 'Initialise Terraform'
inputs:
command: 'init'
workingDirectory: '$(Build.SourcesDirectory)/backend'
- task: TerraformCLI@0
displayName: 'Apply Terraform'
inputs:
command: 'apply'
environmentServiceName: 'Free_Trial'
workingDirectory: '$(Build.SourcesDirectory)/backend'
commandOptions: '-var resource_group_name=$(storage_rg_name) -var storage_account_name=$(storage_account_name)'