-
Notifications
You must be signed in to change notification settings - Fork 0
/
infra-pipeline.yaml
203 lines (198 loc) · 7.38 KB
/
infra-pipeline.yaml
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
trigger:
batch: true
branches:
include:
- main
paths:
exclude:
- ansible/hosts.yaml
pr:
branches:
include:
- main
paths:
exclude:
- ansible/hosts.yaml
resources:
repositories:
- repository: azuredevops-lib
type: github
ref: refs/heads/main
name: bancey/azuredevops-lib
endpoint: bancey
parameters:
- name: local_environments
type: object
default:
- name: wanda
address: "wanda.heimelska.co.uk"
- name: thanos
address: "thanos.heimelska.co.uk"
- name: gamora
address: "gamora.heimelska.co.uk"
- name: hela
address: "hela.heimelska.co.uk"
- name: loki
address: "loki.heimelska.co.uk"
- name: thor
address: "thor.heimelska.co.uk"
- name: terraform_deployments
type: object
default:
- deployment: generate_ansible_inventory
environment: prod
component: inventory
destroy: false
deploy: true
dependsOn: []
- deployment: prod_twingate
environment: prod
component: twingate
destroy: false
deploy: true
dependsOn: []
- deployment: prod_dns
environment: prod
component: dns
destroy: false
deploy: true
localEnvironments:
- thanos
- gamora
dependsOn:
- prod_twingate
- deployment: test_gameserver
environment: test
component: gameserver
destroy: false
deploy: true
dependsOn:
- prod_twingate
- deployment: prod_gameserver
environment: prod
component: gameserver
destroy: false
deploy: true
dependsOn:
- prod_twingate
- test_gameserver
- deployment: wanda_virtual_machines
environment: prod
component: virtual-machines
extraCommandArgs: -var "target_nodes=[\"wanda\"]"
destroy: false
deploy: true
localEnvironments:
- wanda
dependsOn:
- generate_ansible_inventory
- deployment: tiny_virtual_machines
environment: prod
component: virtual-machines
extraCommandArgs: -var "target_nodes=[\"hela\",\"loki\",\"thor\"]"
destroy: false
deploy: true
localEnvironments:
- hela
- loki
- thor
dependsOn:
- generate_ansible_inventory
- name: ansible_deployments
type: object
default:
- deployment: rpi_ansible
environment: prod
playbook: rpi-ha.yaml
secrets:
- keepalived-pass
localEnvironments:
- thanos
- gamora
dependsOn:
- generate_ansible_inventory
variables:
- name: agentImage
value: ubuntu-latest
- name: stateStorageAccount
value: banceystatestor
- name: serviceConnection
value: "MSDN Sub"
stages:
- template: stages/check-hosts-online.yaml@azuredevops-lib
parameters:
dependencies: prod_twingate
keyVaultName: bancey-vault
serviceKeySecretName: Twingate-AzureDevOps-SA-Key
serviceConnection: $(serviceConnection)
hosts: ${{ parameters.local_environments }}
- ${{ each deployment in parameters.terraform_deployments }}:
- stage: ${{ deployment.deployment }}
${{ if and(deployment.localEnvironments, gt(length(join('', deployment.dependsOn)), 0)) }}:
dependsOn: ${{ split(format('{0},{1}', join(',', deployment.dependsOn), 'check_hosts_online'), ',') }}
${{ elseif deployment.localEnvironments }}:
dependsOn: check_hosts_online
${{ else }}:
dependsOn: ${{ deployment.dependsOn }}
${{ if deployment.localEnvironments }}:
condition: and(succeeded(), eq(stageDependencies.check_hosts_online.outputs['check_hosts_online.checkOnline_${{ deployment.localEnvironments[0] }}.online'], 'true'))
${{ else }}: # yamllint disable-line rule:key-duplicates
condition: succeeded()
jobs:
- job: TerraformPlanApply
pool:
vmImage: $(agentImage)
steps:
- ${{ if deployment.localEnvironments }}:
- template: steps/twingate-connect.yaml@azuredevops-lib
parameters:
keyVaultName: bancey-vault
serviceKeySecretName: Twingate-AzureDevOps-SA-Key
serviceConnection: $(serviceConnection)
- ${{ if eq(deployment.component, 'virtual-machines') }}:
- template: steps/ansible.yaml@azuredevops-lib
parameters:
serviceConnection: $(serviceConnection)
keyVaultName: bancey-vault
privateKeySecretName: Packer-Private-Key
- template: steps/terraform.yaml@azuredevops-lib
parameters:
backendStorageAccount: $(stateStorageAccount)
workingDirectory: $(System.DefaultWorkingDirectory)/terraform/components/${{ deployment.component }}
azureRmKey: tfstate/${{ deployment.deployment }}.tfstate
serviceConnection: $(serviceConnection)
variableFilePath: $(System.DefaultWorkingDirectory)/terraform/environments/${{ deployment.environment }}/${{ deployment.environment }}.tfvars
${{ if ne(deployment.extraCommandArgs, '') }}:
extraCommandArgs: ${{ deployment.extraCommandArgs }}
runApply: ${{ and(eq(deployment.deploy, true), eq(variables['Build.SourceBranch'], 'refs/heads/main')) }}
runDestroy: ${{ and(eq(deployment.destroy, true), eq(variables['Build.SourceBranch'], 'refs/heads/main')) }}
- ${{ each ansible_deployment in parameters.ansible_deployments }}:
- stage: ${{ ansible_deployment.deployment }}
${{ if and(ansible_deployment.localEnvironments, gt(length(join('', ansible_deployment.dependsOn)), 0)) }}:
dependsOn: ${{ split(format('{0},{1}', join(',', ansible_deployment.dependsOn), 'check_hosts_online'), ',') }}
${{ elseif ansible_deployment.localEnvironments }}:
dependsOn: check_hosts_online
${{ else }}:
dependsOn: ${{ ansible_deployment.dependsOn }}
${{ if ansible_deployment.localEnvironments }}:
condition: and(succeeded(), eq(stageDependencies.check_hosts_online.outputs['check_hosts_online.checkOnline_${{ ansible_deployment.localEnvironments[0] }}.online'], 'true'))
${{ else }}: # yamllint disable-line rule:key-duplicates
condition: succeeded()
jobs:
- job: AnsibleCheckRun
pool:
vmImage: $(agentImage)
steps:
- template: steps/twingate-connect.yaml@azuredevops-lib
parameters:
keyVaultName: bancey-vault
serviceKeySecretName: Twingate-AzureDevOps-SA-Key
serviceConnection: $(serviceConnection)
- template: steps/ansible.yaml@azuredevops-lib
parameters:
serviceConnection: $(serviceConnection)
keyVaultName: bancey-vault
privateKeySecretName: Packer-Private-Key
playbook: ${{ ansible_deployment.playbook }}
secrets: ${{ ansible_deployment.secrets }}
requirementsFile: ${{ ansible_deployment.requirementsFile }}