-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmerge-apply.yaml
More file actions
128 lines (108 loc) · 3.54 KB
/
Copy pathmerge-apply.yaml
File metadata and controls
128 lines (108 loc) · 3.54 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Merge Pull Request Apply pipeline
# Once Pull request is Merged, Starts with Follow-up Comment on PR Pipeline then applies Terraform Plan.
variables:
- group: config-data
- group: state-data
- name: provider
value: 'azurerm'
- name: directory
value: 'terraform/environments/$(environment_name)' # environment_name variable is defined in pipeline
- name: tfvars-auto-file
value : 'terraform.auto.tfvars.json'
- name: plan-artifact-name
value: 'PlanFile'
- name: plan-artifact-publish-location
value: 'pipeline'
- name: pr-plan-pipeline-definition
value: $(pr_plan_definition)
- name: deploy-tf-file
value: 'deploy.tfplan'
- name: details-text-file
value: 'pipeline-details.txt'
- name: comment-json-file
value: 'pipeline-follow-up-comment.json'
- name: log-level
value: DEBUG
trigger:
branches:
include:
- main # Override trigger from Pipeline settings
pool:
name: '$(environment_name)-motte-pipeline' #configure pool.
demands:
- ImageOverride -equals az-pipeline
stages:
- stage: Apply
displayName: Apply Terraform Plan from pipeline artefact
jobs:
- job: Comment
dependsOn: Apply
steps:
- template: export-pr-id.yml
- template: ../steps/config-data-dynamic-vars.yml
- template: ../steps/state-data-dynamic-vars.yml
- template: ../steps/git-config-pat.yml
- template: ../steps/az-cli-appconfig.yml
parameters:
path: $(tfvars-auto-file)
endpoint: $(APP_CONFIG_ENDPOINT)
- template: ../steps/terraform-init.yml
- task: TerraformTaskV4@4
displayName: Extract Terraform Outputs to Text
inputs:
provider: $(provider)
command: 'custom'
customCommand: 'output'
commandOptions: -json=false
workingDirectory: $(directory)
environmentServiceNameAzureRM: $(service-connection)
outputTo: 'file'
fileName: '$(directory)/$(details-text-file)'
outputFormat: 'default'
env:
ARM_USE_AZUREAD: true
ARM_USE_OIDC: true
TF_IN_AUTOMATION: true
TF_INPUT: 0
TF_LOG: $(log-level)
- template: build-apply-comment-as-file.yml
parameters:
inputFile: "$(directory)/$(details-text-file)"
outputFile: "$(directory)/$(comment-json-file)"
buildId: "$(Build.BuildId)"
- template: ../steps/az-cli-post-pr-comment.yml
parameters:
PR_ID: $(OriginalPullRequestId)
comment_json_file: $(comment-json-file)
- job: Apply
steps:
- task: DownloadPipelineArtifact@2
displayName: Download Plan file artifact
inputs:
source: 'specific'
project: $(System.TeamProjectId)
definition: $(pr-plan-pipeline-definition)
artifact: $(plan-artifact-name)
buildVersionToDownload: latest
targetPath: $(Build.SourcesDirectory)/$(directory)
- template: ../steps/config-data-dynamic-vars.yml
- template: ../steps/state-data-dynamic-vars.yml
- template: ../steps/git-config-pat.yml
- template: ../steps/az-cli-appconfig.yml
parameters:
path: $(tfvars-auto-file)
endpoint: $(APP_CONFIG_ENDPOINT)
- template: ../steps/terraform-init.yml
- task: TerraformTaskV4@4
displayName: Terraform Apply
inputs:
provider: $(provider)
command: 'apply'
workingDirectory: $(directory)
environmentServiceNameAzureRM: $(service-connection)
env:
ARM_USE_AZUREAD: true
ARM_USE_OIDC: true
TF_INPUT: 0
TF_LOG: $(log-level)
- template: ../steps/git-config-reset.yml