Repository navigation
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
246 lines (238 loc) · 9.73 KB
/
Copy pathazure-pipelines.yml
File metadata and controls
246 lines (238 loc) · 9.73 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
batch: true
branches:
include:
- master
pool: 'Newlocal'
variables:
- group: vg1
stages:
- stage: build_and_test
jobs:
- job: "show_subscription_and_show_current_dir"
steps:
- script: |
az login --service-principal -u $(ARM_CLIENT_ID) -p $(ARM_CLIENT_SECRET) --tenant $(ARM_TENANT_ID) && az account list
displayName: 'show subscription'
- script: pwd && ls -ltra && env
displayName: 'show current dir'
- job: "Install_prerequsites"
steps:
- task: Bash@3
name: "install_jq_make_pip"
inputs:
targetType: 'inline'
script: |
sudo apt-get update -y && sudo apt-get install jq make python3-pip python3 -y
workingDirectory: 'terraform/azure'
- task: Bash@3
name: "install_terragrunt"
inputs:
targetType: 'inline'
script: |
if [ -f /usr/local/bin/terragrunt ]; then
echo "terragrunt is installed"
else
wget https://github.com/gruntwork-io/terragrunt/releases/download/v0.48.3/terragrunt_linux_amd64
mv terragrunt_linux_amd64 terragrunt
sudo cp terragrunt /usr/local/bin/
fi
workingDirectory: 'terraform/azure'
- task: Bash@3
name: "install_terraform"
inputs:
targetType: 'inline'
script: |
if [ -f /usr/local/bin/terraform ]; then
echo "terraform is installed"
else
wget https://releases.hashicorp.com/terraform/1.5.1/terraform_1.5.1_linux_amd64.zip
sudo apt install zip -y && sudo unzip -ov "terraform_*amd64.zip" -d /usr/local/bin/
terraform version
fi
workingDirectory: 'terraform/azure'
- job: "terragrunt_init_validate"
dependsOn: "Install_prerequsites"
steps:
- task: Bash@3
name: "terragrunt_init_remotestate"
inputs:
targetType: 'inline'
script: |
# Write your commands here
source ../../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
terragrunt init
workingDirectory: 'terraform/azure/terragrunt/run_init/remotestate'
- task: Bash@3
name: "terragrunt_init_infra"
condition: eq(variables.first_iteration, false)
inputs:
targetType: 'inline'
script: |
# Write your commands here
source ../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
terragrunt run-all init --terragrunt-non-interactive --terragrunt-working-dir .
workingDirectory: 'terraform/azure/terragrunt/orchestration'
- task: Bash@3
name: "terragrunt_validate_remotestate"
inputs:
targetType: 'inline'
script: |
# Write your commands here
source ../../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
terragrunt validate
workingDirectory: 'terraform/azure/terragrunt/run_init/remotestate'
- task: Bash@3
name: "terragrunt_validate_infra"
condition: eq(variables.first_iteration, false)
inputs:
targetType: 'inline'
script: |
# Write your commands here
source ../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
terragrunt validate
workingDirectory: 'terraform/azure/terragrunt/orchestration'
- job: "terragrunt_plan"
dependsOn: "terragrunt_init_validate"
steps:
- task: Bash@3
name: "terragrunt_plan_remotestate"
inputs:
targetType: 'inline'
script: |
# Write your commands here
source ../../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
terragrunt plan
workingDirectory: 'terraform/azure/terragrunt/run_init/remotestate'
- task: Bash@3
name: "terraform_plan_infra"
condition: eq(variables.first_iteration, false)
inputs:
targetType: 'inline'
script: |
source ../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
terragrunt run-all plan --terragrunt-non-interactive --terragrunt-working-dir .
workingDirectory: 'terraform/azure/terragrunt/orchestration'
- stage: scan_using_checkov
dependsOn: 'build_and_test'
jobs:
- job: "test_using_checkov"
steps:
- task: Bash@3
name: "install_checkov"
inputs:
targetType: 'inline'
script: |
pip3 install checkov
checkov --directory `pwd`
workingDirectory: 'terraform/azure/modules'
continueOnError: true
- stage: publish_artifact
dependsOn: 'build_and_test'
jobs:
- job: "publish_artifacts"
steps:
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifact: 'terraform'
publishLocation: 'pipeline'
- stage: start_deploy
dependsOn: 'publish_artifact'
jobs:
- deployment: start_deploy_approval
displayName: start_deploy_approval # friendly name to display in the UI
environment: 'test-approval-check' # target environment name and optionally a resource-name to record the deployment history; format: <environment-name>.<resource-name>
strategy: # see deployment strategy schema
runOnce:
deploy:
steps:
- script: echo "starting deployment"
- job: "Install_prerequsites"
dependsOn: 'start_deploy_approval'
steps:
- task: Bash@3
name: "install_jq_make"
inputs:
targetType: 'inline'
script: |
sudo apt-get install jq -y && sudo apt-get install make -y
workingDirectory: 'terraform/azure'
- task: Bash@3
name: "install_terragrunt"
inputs:
targetType: 'inline'
script: |
if [ -f /usr/local/bin/terragrunt ]; then
echo "terragrunt is installed"
else
wget https://github.com/gruntwork-io/terragrunt/releases/download/v0.48.3/terragrunt_linux_amd64
mv terragrunt_linux_amd64 terragrunt
sudo cp terragrunt /usr/local/bin/
fi
workingDirectory: 'terraform/azure'
- task: Bash@3
name: "install_terraform"
inputs:
targetType: 'inline'
script: |
if [ -f /usr/local/bin/terraform ]; then
echo "terraform is installed"
else
wget https://releases.hashicorp.com/terraform/1.5.1/terraform_1.5.1_linux_amd64.zip
sudo apt install zip -y && sudo unzip -ov "terraform_*amd64.zip" -d /usr/local/bin/
terraform version
fi
workingDirectory: 'terraform/azure'
- job: "terragrunt_init_statefile"
dependsOn: 'start_deploy_approval'
steps:
- task: Bash@3
name: "terraform_migrate_state_to_backend"
condition: eq(variables.local_state_file, true)
inputs:
targetType: 'inline'
script: |
source ../../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
terragrunt init
terragrunt apply -auto-approve && cp archive/terragrunt.hcl ../ && terragrunt init -migrate-state --force-copy
workingDirectory: 'terraform/azure/terragrunt/run_init/remotestate'
- task: Bash@3
name: "terragrunt_init_remotestate"
condition: eq(variables.local_state_file, false)
inputs:
targetType: 'inline'
script: |
source ../../set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
cp archive/terragrunt.hcl ../ && terragrunt init
terragrunt apply -auto-approve
workingDirectory: 'terraform/azure/terragrunt/run_init/remotestate'
- stage: finalize_depoyment
dependsOn: 'start_deploy'
jobs:
- job: "terragrunt_apply_all"
condition: eq(variables.terragrunt_action, 'apply')
steps:
- task: Bash@3
name: "terragrunt_apply_all"
inputs:
targetType: 'inline'
script: |
source ./set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
make apply-all-ha
workingDirectory: 'terraform/azure/terragrunt'
- job: "terragrunt_destroy_all"
condition: eq(variables.terragrunt_action, 'destroy')
steps:
- task: Bash@3
name: "terragrunt_destroy_all"
inputs:
targetType: 'inline'
script: |
source ./set-env.sh && export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET) && export ARM_CLIENT_ID=$(ARM_CLIENT_ID) && export ARM_SUBSCRIPTION_ID=$(ARM_SUBSCRIPTION_ID) && export ARM_TENANT_ID=$(ARM_TENANT_ID)
make destroy-all-ha
workingDirectory: 'terraform/azure/terragrunt'