-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpr-plan.yaml
More file actions
92 lines (79 loc) · 2.6 KB
/
Copy pathpr-plan.yaml
File metadata and controls
92 lines (79 loc) · 2.6 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
# Pull Request (PR) Plan pipeline
# Start with a app config from Azure then Creates a Terraform Plan through a Service Connection, to post as PR Comment.
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: deploy-tf-file
value: 'deploy.tfplan'
- name: plan-artifact-name
value: 'PlanFile'
- name: plan-artifact-publish-location
value: 'pipeline'
- name: plan-text-file
value: 'plan.txt'
- name: comment-json-file
value: 'terraform-plan-comment.json'
- name: log-level
value: DEBUG
trigger:
branches:
include: # trigger is done through branch policy in devops
- none
pool:
name: '$(environment_name)-motte-pipeline' #configure pool.
demands:
- ImageOverride -equals az-pipeline
stages:
- stage: Plan
displayName: Plan
condition: eq(variables['Build.Reason'], 'PullRequest')
jobs:
- job: Generate
steps:
- 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 Plan
inputs:
provider: $(provider)
command: 'plan'
workingDirectory: $(directory)
commandOptions: -out=$(deploy-tf-file)
environmentServiceNameAzureRM: $(service-connection)
env:
ARM_USE_AZUREAD: true
ARM_USE_OIDC: true
TF_IN_AUTOMATION: true
TF_INPUT: 0
TF_LOG: $(log-level)
- task: PublishPipelineArtifact@1
displayName: Publish Plan File as an artifact
inputs:
targetPath: '$(directory)/$(deploy-tf-file)'
artifactName: $(plan-artifact-name)
publishLocation: $(plan-artifact-publish-location)
- script: |
terraform show -no-color $(deploy-tf-file) > $(plan-text-file)
workingDirectory: $(directory)
displayName: Convert plan to text
- template: build-pr-comment-as-file.yml
parameters:
inputFile: "$(directory)/$(plan-text-file)"
outputFile: "$(directory)/$(comment-json-file)"
- template: ../steps/az-cli-post-pr-comment.yml
parameters:
PR_ID: $(System.PullRequest.PullRequestId)
comment_json_file: $(comment-json-file)
- template: ../steps/git-config-reset.yml