-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmain.tf
More file actions
286 lines (242 loc) · 8.54 KB
/
main.tf
File metadata and controls
286 lines (242 loc) · 8.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
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
resource "google_compute_network" "management_network" {
name = "management-network"
auto_create_subnetworks = false
}
resource "google_compute_firewall" "management_firewall" {
name = "management-firewall"
network = google_compute_network.management_network.name
priority = 1000
direction = "INGRESS"
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
}
allow {
protocol = "udp"
ports = ["3003"]
}
source_ranges = [ var.controlling_subnet, google_compute_subnetwork.management_subnet.ip_cidr_range ]
}
resource "google_compute_subnetwork" "management_subnet" {
name = var.management_subnet_name
ip_cidr_range = var.management_subnet_cidr_block
region = var.region
network = google_compute_network.management_network.id
private_ip_google_access = true
}
resource "google_compute_network" "client_network" {
name = "client-network"
auto_create_subnetworks = false
}
resource "google_compute_firewall" "client_firewall" {
name = "client-firewall"
network = google_compute_network.client_network.name
priority = 1000
direction = "INGRESS"
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = [ "0.0.0.0/0" ]
}
resource "google_compute_subnetwork" "client_subnet" {
name = var.client_subnet_name
ip_cidr_range = var.client_subnet_cidr_block
region = var.region
network = google_compute_network.client_network.id
private_ip_google_access = true
}
resource "google_compute_network" "server_network" {
name = "server-network"
auto_create_subnetworks = false
}
resource "google_compute_firewall" "server_firewall" {
name = "server-firewall"
network = google_compute_network.server_network.name
priority = 1000
direction = "INGRESS"
allow {
protocol = "icmp"
}
allow {
protocol = "tcp"
}
allow {
protocol = "udp"
}
source_ranges = [ google_compute_subnetwork.server_subnet.ip_cidr_range ]
}
resource "google_compute_subnetwork" "server_subnet" {
name = var.server_subnet_name
ip_cidr_range = var.server_subnet_cidr_block
region = var.region
network = google_compute_network.server_network.id
private_ip_google_access = true
}
resource "google_compute_address" "management_external_address" {
name = format("management-external-address-%d", count.index)
address_type = "EXTERNAL"
region = var.region
count = 2
}
resource "google_compute_address" "client_external_address" {
name = "client-external-address"
address_type = "EXTERNAL"
region = var.region
}
resource "google_compute_address" "primary_mgmt_address" {
name = "primary-mgmt-address"
address_type = "INTERNAL"
subnetwork = google_compute_subnetwork.management_subnet.id
region = var.region
}
resource "google_compute_address" "primary_client_address" {
name = "primary-client-address"
address_type = "INTERNAL"
subnetwork = google_compute_subnetwork.client_subnet.id
region = var.region
}
resource "google_compute_address" "primary_server_address" {
name = "primary-server-address"
address_type = "INTERNAL"
subnetwork = google_compute_subnetwork.server_subnet.id
region = var.region
}
resource "google_compute_instance" "adc_primary" {
name = "adcinstance-primary"
machine_type = var.machine_type
zone = var.zones[0]
boot_disk {
device_name = "boot"
auto_delete = true
initialize_params {
image = var.image
}
}
metadata_startup_script = <<-EOF
<NS-PRE-BOOT-CONFIG>
<NS-CONFIG>
set systemparameter -promptString "%u@%s"
add ns ip ${google_compute_address.primary_server_address.address} ${cidrnetmask(var.server_subnet_cidr_block)} -type SNIP
add ns ip ${google_compute_address.primary_client_address.address} ${cidrnetmask(var.client_subnet_cidr_block)} -type VIP
add ns ip ${google_compute_address.secondary_client_address.address} ${cidrnetmask(var.client_subnet_cidr_block)} -type VIP
add ha node 1 ${google_compute_address.secondary_mgmt_address.address} -inc ENABLED
set ns rpcNode ${google_compute_address.primary_mgmt_address.address} -password ${var.citrixadc_rpc_node_password} -secure YES
set ns rpcNode ${google_compute_address.secondary_mgmt_address.address} -password ${var.citrixadc_rpc_node_password} -secure YES
</NS-CONFIG>
</NS-PRE-BOOT-CONFIG>
EOF
metadata = {
ssh-keys = "nsroot:${file(var.public_ssh_key_file)}"
}
service_account {
scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/cloud-platform"
]
}
# Management NIC
network_interface {
subnetwork = google_compute_subnetwork.management_subnet.name
network_ip = google_compute_address.primary_mgmt_address.address
access_config {
nat_ip = google_compute_address.management_external_address[0].address
}
}
# Client NIC
network_interface {
subnetwork = google_compute_subnetwork.client_subnet.name
network_ip = google_compute_address.primary_client_address.address
access_config {
nat_ip = google_compute_address.client_external_address.address
}
}
# Server NIC
network_interface {
subnetwork = google_compute_subnetwork.server_subnet.name
network_ip = google_compute_address.primary_server_address.address
}
}
resource "google_compute_address" "secondary_mgmt_address" {
name = "secondary-mgmt-address"
address_type = "INTERNAL"
subnetwork = google_compute_subnetwork.management_subnet.id
region = var.region
}
resource "google_compute_address" "secondary_client_address" {
name = "secondary-client-address"
address_type = "INTERNAL"
subnetwork = google_compute_subnetwork.client_subnet.id
region = var.region
}
resource "google_compute_address" "secondary_server_address" {
name = "secondary-server-address"
address_type = "INTERNAL"
subnetwork = google_compute_subnetwork.server_subnet.id
region = var.region
}
resource "google_compute_instance" "adc_secondary" {
name = "adcinstance-secondary"
machine_type = var.machine_type
zone = var.zones[1]
boot_disk {
device_name = "boot"
auto_delete = true
initialize_params {
image = var.image
}
}
metadata_startup_script = <<-EOF
<NS-PRE-BOOT-CONFIG>
<NS-CONFIG>
set systemparameter -promptString "%u@%s"
add ns ip ${google_compute_address.secondary_server_address.address} ${cidrnetmask(var.server_subnet_cidr_block)} -type SNIP
add ns ip ${google_compute_address.secondary_client_address.address} ${cidrnetmask(var.client_subnet_cidr_block)} -type VIP
add ns ip ${google_compute_address.primary_client_address.address} ${cidrnetmask(var.client_subnet_cidr_block)} -type VIP
add ha node 1 ${google_compute_address.primary_mgmt_address.address} -inc ENABLED
set ns rpcNode ${google_compute_address.primary_mgmt_address.address} -password ${var.citrixadc_rpc_node_password} -secure YES
set ns rpcNode ${google_compute_address.secondary_mgmt_address.address} -password ${var.citrixadc_rpc_node_password} -secure YES
</NS-CONFIG>
</NS-PRE-BOOT-CONFIG>
EOF
metadata = {
ssh-keys = "nsroot:${file(var.public_ssh_key_file)}"
}
service_account {
scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/cloud-platform"
]
}
# Management NIC
network_interface {
subnetwork = google_compute_subnetwork.management_subnet.name
network_ip = google_compute_address.secondary_mgmt_address.address
access_config {
nat_ip = google_compute_address.management_external_address[1].address
}
}
# Client NIC
network_interface {
subnetwork = google_compute_subnetwork.client_subnet.name
network_ip = google_compute_address.secondary_client_address.address
}
# Server NIC
network_interface {
subnetwork = google_compute_subnetwork.server_subnet.name
network_ip = google_compute_address.secondary_server_address.address
}
# Force ordering so primary node selection is deterministic
depends_on = [google_compute_instance.adc_primary]
}