-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
qwiklabs.jinja
executable file
·301 lines (283 loc) · 9.23 KB
/
qwiklabs.jinja
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
{% import "path_utils.jinja" as path_utils with context %}
{% set project = env["project"] %}
{% set deployment = env["deployment"] %}
{% set zone = properties["zone"] %}
{% set saAccount = "bootcampadmin" %}
{# Win AD#}
{% set ad_name = "dc" %}
{# Expand resource input parameters into full URLs#}
{% set adImageBasenames = {
2016:"windows-server-2016-dc-core-v20170214"
}
%}
{% set ad_image_path = "projects/windows-cloud/global/images/" ~
adImageBasenames[properties["adImage"]]
%}
{% set domainDNSName = properties["domainDNSName"] %}
{% set adMachineType = properties["adMachineType"] %}
{% set adBootDiskType = path_utils.diskTypePath(zone, properties["adBootDiskType"]) %}
{% set adBootDiskSizeGb = properties["adBootDiskSizeGb"] %}
{# MSSQL#}
{% set sql_name = "cluster-sql" %}
{# Expand resource input parameters into full URLs#}
{% set sqlImageBasenames = {
2016:"sql-2016-enterprise-windows-2016-dc-v20170214"
}
%}
{% set sql_image_path = "projects/windows-sql-cloud/global/images/" ~
sqlImageBasenames[properties["sqlImage"]]
%}
{% set sqlMachineType = properties["sqlMachineType"] %}
{% set sqlBootDiskType = path_utils.diskTypePath(zone, properties["sqlBootDiskType"]) %}
{% set sqlBootDiskSizeGb = properties["sqlBootDiskSizeGb"] %}
{% set sqlNodes = properties["sqlNodes"] %}
{% set bootDiskType = properties["bootDiskType"] %}
{% set bootDiskSizeGb = properties["bootDiskSizeGb"] %}
{% set hasExternalIP = properties["externalIP"] != "None" %}
{# Software status only works if the VM has an external IP. #}
{% set enableStatusWaiter = hasExternalIP %}
{# Web Machines#}
{% set webMachineType = properties["webMachineType"] %}
{% set web_image_path = "projects/click-to-deploy-images/global/images/asp-windows-2016-v20170304" %}
{% set dev_image_path = "projects/click-to-deploy-images/global/images/vs-windows-2016-v20170304" %}
{# Waiter Variables#}
{# 18 minute timeout for sql install.#}
{% set WAITER_TIMEOUT = 1080 %}
{# 20 minutes timeout for AD install#}
{% set AD_WAITER_TIMEOUT = 1200 %}
{% set adStatusVariablePath = "ad" %}
{% set webStatusVariablePath = "web" %}
{# 18 minute timeout for SQL install.#}
{% set SQL_WAITER_TIMEOUT = 1080 %}
{% set sqlStatusVariablePath = "mssql" %}
{# 15 minute timeout for availabilty group install.#}
{% set SUB_WAITER_TIMEOUT = 900 %}
{% macro nodes() -%}
{% for instance in range(1, properties["sqlNodes"] + 1) -%}
{{ ("%s-sql-%d"|format((env["deployment"]|truncate(9,true,"")), instance)) + '|' }}
{%- endfor %}
{%- endmacro %}
resources:
{# Passwords#}
- name: generate-safe-password
type: password.py
properties:
length: 14
includeSymbols: True
- name: sa-password
type: password.py
properties:
length: 14
includeSymbols: True
- name: sql-sa-password
type: password.py
properties:
length: 14
includeSymbols: True
{# Network Config#}
- name: qwiklabs_network
type: qwiklabs_network.jinja
properties:
deployment: {{ deployment }}
zone: {{ zone }}
sqlNodes: {{ sqlNodes }}
{# Machine Configs#}
{# AD#}
- name: qwiklabs_ad
type: qwiklabs_ad.jinja
properties:
name: {{ ad_name }}
deployment: {{ deployment }}
zone: {{ zone }}
image: {{ ad_image_path }}
machineType: {{ adMachineType }}
network: {{ deployment }}-net
subnetwork: {{ deployment }}-sub0
networkIP: 10.0.0.100
bootDiskType: {{ adBootDiskType }}
bootDiskSizeGb: {{ adBootDiskSizeGb }}
domainDNSName: {{ domainDNSName }}
allNodes: {{ nodes() | trim }}
safeModePassword: $(ref.generate-safe-password.password)
saAccount: {{ saAccount }}
saPassword: "$(ref.sa-password.password)"
statusConfigUrl: $(ref.software-status.config-url)
statusVariablePath: {{ adStatusVariablePath }}
statusUptimeDeadline: {{ AD_WAITER_TIMEOUT }}
{# SQL Machines, Start count with 1#}
{% for index in range(sqlNodes) %}
- name: {{ deployment }}-node-{{ index + 1}}
type: qwiklabs_sql_nodes.jinja
properties:
name: {{ sql_name }}{{ index + 1}}
deployment: {{ deployment }}
zone: {{ zone }}
image: {{ sql_image_path }}
machineType: {{ sqlMachineType }}
network: {{ deployment }}-net
subnetwork: {{ deployment }}-sub{{ index + 1 }}
networkIP: 10.{{ index + 1 }}.0.4
routeIP: 10.{{ index + 1 }}.1.4
listnerIP: 10.{{ index + 1 }}.1.5
bootDiskType: {{ sqlBootDiskType }}
bootDiskSizeGb: {{ sqlBootDiskSizeGb }}
sequence: {{ index + 1}}
domainDNSName: {{ domainDNSName }}
adHost: {{ ad_name }}
allNodes: {{ nodes() | trim }}
saAccount: {{ saAccount }}
saPassword: $(ref.sa-password.password)
saSQLPassword: $(ref.sql-sa-password.password)
statusConfigUrl: $(ref.software-status.config-url)
statusVariablePath: {{ sqlStatusVariablePath }}
statusUptimeDeadline: {{ SQL_WAITER_TIMEOUT }}
{% endfor %}
{# Web Machines#}
- name: qwiklabs_web
type: qwiklabs_web.jinja
properties:
deployment: {{ deployment }}
zone: {{ zone }}
image: {{ web_image_path }}
devImage: {{ dev_image_path }}
machineType: {{ webMachineType }}
network: {{ deployment }}-net
subnetwork: {{ deployment }}-sub0
bootDiskType: {{ adBootDiskType }}
bootDiskSizeGb: {{ adBootDiskSizeGb }}
domainDNSName: {{ domainDNSName }}
saAccount: {{ saAccount }}
saPassword: "$(ref.sa-password.password)"
statusConfigUrl: $(ref.software-status.config-url)
statusVariablePath: {{ webStatusVariablePath }}
statusUptimeDeadline: {{ AD_WAITER_TIMEOUT }}
{# Firewall Configs
# Create Internal Firewall Rules#}
- name: {{ deployment }}-allow-internal-ports
type: compute.v1.firewall
properties:
allowed:
- IPProtocol: TCP
ports: [ 1-65535 ]
- IPProtocol: UDP
ports: [ 1-65535 ]
- IPProtocol: ICMP
sourceRanges: [10.0.0.0/24,10.1.0.0/24,10.2.0.0/24]
network: $(ref.{{ deployment }}-net.selfLink)
metadata:
dependsOn:
- {{ deployment }}-net
{% if properties["enableTcp3389"] %}
- name: {{ deployment }}-tcp-3389
type: compute.v1.firewall
properties:
network: $(ref.{{ deployment }}-net.selfLink)
sourceRanges: ["0.0.0.0/0"]
targetTags: ["{{ deployment }}-tcp-3389"]
allowed:
- IPProtocol: TCP
ports: ["3389"]
metadata:
dependsOn:
- {{ deployment }}-net
{% endif %}
{% if properties["enableTcp1433"] %}
- name: {{ deployment }}-tcp-1433
type: compute.v1.firewall
properties:
network: $(ref.{{ deployment }}-net.selfLink)
sourceRanges: ["0.0.0.0/0"]
targetTags: ["{{ deployment }}-tcp-1433"]
allowed:
- IPProtocol: TCP
ports: ["1433"]
metadata:
dependsOn:
- {{ deployment }}-net
{% endif %}
{% if properties["enableTcp5022"] %}
- name: {{ deployment }}-tcp-5022
type: compute.v1.firewall
properties:
network: $(ref.{{ deployment }}-net.selfLink)
sourceRanges: ["0.0.0.0/0"]
targetTags: ["{{ deployment }}-tcp-5022"]
allowed:
- IPProtocol: TCP
ports: ["5022"]
metadata:
dependsOn:
- {{ deployment }}-net
{% endif %}
{% if properties["enableTcp80"] %}
- name: {{ deployment }}-tcp-80
type: compute.v1.firewall
properties:
network: $(ref.{{ deployment }}-net.selfLink)
sourceRanges: ["0.0.0.0/0"]
targetTags: ["{{ deployment }}-tcp-80"]
allowed:
- IPProtocol: TCP
ports: ["80"]
metadata:
dependsOn:
- {{ deployment }}-net
{% endif %}
{% if properties["enableTcp443"] %}
- name: {{ deployment }}-tcp-443
type: compute.v1.firewall
properties:
network: $(ref.{{ deployment }}-net.selfLink)
sourceRanges: ["0.0.0.0/0"]
targetTags: ["{{ deployment }}-tcp-443"]
allowed:
- IPProtocol: TCP
ports: ["443"]
metadata:
dependsOn:
- {{ deployment }}-net
{% endif %}
{% if properties["enableTcp8172"] %}
- name: {{ deployment }}-tcp-8172
type: compute.v1.firewall
properties:
network: $(ref.{{ deployment }}-net.selfLink)
sourceRanges: ["0.0.0.0/0"]
targetTags: ["{{ deployment }}-tcp-8172"]
allowed:
- IPProtocol: TCP
ports: ["8172"]
metadata:
dependsOn:
- {{ deployment }}-net
{% endif %}
{# RuntimeConfigs#}
- name: software-status
type: software_status.py
properties:
successNumber: 2
timeout: {{ WAITER_TIMEOUT }}
waiterDependsOn:
- {{ ad_name }}
{% for index in range(sqlNodes) %}
- {{ sql_name }}{{ index + 1}}
{% endfor %}
outputs:
- name: WebMachineIP
value: $(ref.web.networkInterfaces[0].accessConfigs[0].natIP)
- name: DomainName
value: {{ domainDNSName }}
- name: ServiceAccountName
value: {{ saAccount }}
- name: ServiceAccountPassword
value: $(ref.sa-password.password)
- name: ASPWebSite
value: http://$(ref.web.networkInterfaces[0].accessConfigs[0].natIP)/
- name: SQLSaPassword
value: $(ref.sql-sa-password.password)
- name: DevMachineIP
value: $(ref.dev.networkInterfaces[0].accessConfigs[0].natIP)
- name: deployment
value: {{ deployment }}
- name: project
value: {{ project }}