-
Notifications
You must be signed in to change notification settings - Fork 8
/
instance.tf
208 lines (174 loc) · 6.73 KB
/
instance.tf
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
data "ibm_is_ssh_key" "ssh_key" {
name = var.SSH_PUBLIC_KEY
}
// HA Password
resource "random_string" "ha_password" {
length = 8
special = false
}
resource "ibm_is_volume" "logDisk1" {
// Name must be lower case
name = "${var.CLUSTER_NAME}-logdisk1-${random_string.random_suffix.result}"
profile = "10iops-tier"
zone = var.ZONE
}
resource "ibm_is_volume" "logDisk2" {
// Name must be lower case
name = "${var.CLUSTER_NAME}-logdisk2-${random_string.random_suffix.result}"
profile = "10iops-tier"
zone = var.ZONE
}
resource "ibm_is_floating_ip" "publicip" {
name = "${var.CLUSTER_NAME}-publicip-${random_string.random_suffix.result}"
zone = var.ZONE
}
resource "ibm_is_floating_ip" "publicip2" {
name = "${var.CLUSTER_NAME}-hamgmt-fgt1-${random_string.random_suffix.result}"
zone = var.ZONE
}
resource "ibm_is_floating_ip" "publicip3" {
name = "${var.CLUSTER_NAME}-hamgmt-fgt2-${random_string.random_suffix.result}"
zone = var.ZONE
}
resource "ibm_is_virtual_network_interface_floating_ip" "public_ip" {
virtual_network_interface = ibm_is_virtual_network_interface.vni-active["interface1"].id
floating_ip = ibm_is_floating_ip.publicip.id
}
resource "ibm_is_virtual_network_interface_floating_ip" "public_ip2" {
virtual_network_interface = ibm_is_virtual_network_interface.vni-active["interface4"].id
floating_ip = ibm_is_floating_ip.publicip2.id
}
resource "ibm_is_virtual_network_interface_floating_ip" "public_ip3" {
virtual_network_interface = ibm_is_virtual_network_interface.vni-passive["interface4"].id
floating_ip = ibm_is_floating_ip.publicip3.id
}
//Primary Fortigate
resource "ibm_is_instance" "fgt1" {
name = "${var.CLUSTER_NAME}-fortigate1-${random_string.random_suffix.result}"
image = ibm_is_image.vnf_custom_image.id
profile = var.PROFILE
resource_group = data.ibm_resource_group.rg.id
primary_network_attachment {
name = "${var.CLUSTER_NAME}-port1-fgt1-att-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-active["interface1"].id
}
}
network_attachments {
name = "${var.CLUSTER_NAME}-port2-fgt1-att-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-active["interface2"].id
}
}
network_attachments {
name = "${var.CLUSTER_NAME}-port3-fgt1-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-active["interface3"].id
}
}
network_attachments {
name = "${var.CLUSTER_NAME}-port4-fgt1-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-active["interface4"].id
}
}
volumes = [ibm_is_volume.logDisk1.id]
vpc = data.ibm_is_vpc.vpc1.id
zone = var.ZONE
user_data = data.template_file.userdata_active.rendered
keys = [data.ibm_is_ssh_key.ssh_key.id]
// Timeout issues persist. See https://www.ibm.com/cloud/blog/timeout-errors-with-ibm-cloud-schematics
timeouts {
create = "60m"
update = "60m"
delete = "60m"
}
// Force IBM to recover from perpetual 'starting state' see:
// https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_instance#force_recovery_time
force_recovery_time = 20
}
// Secondary FortiGate
resource "ibm_is_instance" "fgt2" {
name = "${var.CLUSTER_NAME}-fortigate2-${random_string.random_suffix.result}"
image = ibm_is_image.vnf_custom_image.id
profile = var.PROFILE
resource_group = data.ibm_resource_group.rg.id
primary_network_attachment {
name = "${var.CLUSTER_NAME}-port1-fgt2-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-passive["interface1"].id
}
}
network_attachments {
name = "${var.CLUSTER_NAME}-port2-fgt2-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-passive["interface2"].id
}
}
network_attachments {
name = "${var.CLUSTER_NAME}-port3-fgt2-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-passive["interface3"].id
}
}
network_attachments {
name = "${var.CLUSTER_NAME}-port4-fgt2-${random_string.random_suffix.result}"
virtual_network_interface {
id = ibm_is_virtual_network_interface.vni-passive["interface4"].id
}
}
volumes = [ibm_is_volume.logDisk2.id]
vpc = data.ibm_is_vpc.vpc1.id
zone = var.ZONE
user_data = data.template_file.userdata_passive.rendered
keys = [data.ibm_is_ssh_key.ssh_key.id]
//Timeout issues persist. See https://www.ibm.com/cloud/blog/timeout-errors-with-ibm-cloud-schematics
timeouts {
create = "60m"
update = "60m"
delete = "60m"
}
// Force IBM to recover from perpetual 'starting state' see:
// https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_instance#force_recovery_time
force_recovery_time = 20
}
// Use for bootstrapping cloud-init
// Active Config template.
//TODO: files need to be vars
data "template_file" "userdata_active" {
template = file("user_data_active.conf")
vars = {
fgt_1_static_port1 = var.FGT1_STATIC_IP_PORT1
fgt_1_static_port2 = var.FGT1_STATIC_IP_PORT2
fgt_1_static_port3 = var.FGT1_STATIC_IP_PORT3
fgt_1_static_port4 = var.FGT1_STATIC_IP_PORT4
fgt_2_static_port1 = var.FGT2_STATIC_IP_PORT1
fgt_2_static_port2 = var.FGT2_STATIC_IP_PORT2
fgt_2_static_port3 = var.FGT2_STATIC_IP_PORT3
fgt_2_static_port4 = var.FGT2_STATIC_IP_PORT4
netmask = var.NETMASK
ibm_api_key = var.IBMCLOUD_API_KEY
region = var.IBMREGION[var.REGION]
fgt1_port_4_mgmt_gateway = var.FGT1_PORT4_MGMT_GATEWAY
ha_password = random_string.ha_password.result
}
}
// Passive Config Template.
data "template_file" "userdata_passive" {
template = file("user_data_passive.conf")
vars = {
fgt_1_static_port1 = var.FGT1_STATIC_IP_PORT1
fgt_1_static_port2 = var.FGT1_STATIC_IP_PORT2
fgt_1_static_port3 = var.FGT1_STATIC_IP_PORT3
fgt_1_static_port4 = var.FGT1_STATIC_IP_PORT4
fgt_2_static_port1 = var.FGT2_STATIC_IP_PORT1
fgt_2_static_port2 = var.FGT2_STATIC_IP_PORT2
fgt_2_static_port3 = var.FGT2_STATIC_IP_PORT3
fgt_2_static_port4 = var.FGT2_STATIC_IP_PORT4
netmask = var.NETMASK
ibm_api_key = var.IBMCLOUD_API_KEY
region = var.IBMREGION[var.REGION]
fgt2_port_4_mgmt_gateway = var.FGT2_PORT4_MGMT_GATEWAY
ha_password = random_string.ha_password.result
}
}