-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.tf
235 lines (208 loc) · 8.13 KB
/
main.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
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
resource "azurerm_public_ip" "stcv" {
count = var.instance_count
name = "publicip-${var.instance_name}-${count.index}"
location = var.resource_group_location
resource_group_name = var.resource_group_name
allocation_method = "Dynamic"
}
resource "azurerm_network_security_group" "mgmt_plane" {
name = "nsg-mgmt-${var.instance_name}"
location = var.resource_group_location
resource_group_name = var.resource_group_name
security_rule {
name = "ssh"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefixes = var.ingress_cidr_blocks
destination_address_prefix = "*"
}
security_rule {
name = "stc-chassis"
priority = 110
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "40004"
source_address_prefixes = var.ingress_cidr_blocks
destination_address_prefix = "*"
}
security_rule {
name = "stc-chassis-ready"
priority = 130
direction = "Inbound"
access = "Allow"
protocol = "Udp"
source_port_range = "*"
destination_port_range = "40004"
source_address_prefixes = var.ingress_cidr_blocks
destination_address_prefix = "*"
}
security_rule {
name = "stc-chassis-ready-QUIC"
priority = 131
direction = "Inbound"
access = "Allow"
protocol = "Udp"
source_port_range = "*"
destination_port_range = "40005"
source_address_prefixes = var.ingress_cidr_blocks
destination_address_prefix = "*"
}
security_rule {
name = "stc-portgroup"
priority = 120
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "51204"
source_address_prefixes = var.ingress_cidr_blocks
destination_address_prefix = "*"
}
security_rule {
name = "stc-portgroup-QUIC"
priority = 121
direction = "Inbound"
access = "Allow"
protocol = "Udp"
source_port_range = "*"
destination_port_range = "51204"
source_address_prefixes = var.ingress_cidr_blocks
destination_address_prefix = "*"
}
security_rule {
name = "bll-ephemeral"
description = "All outbound traffic back to BLL"
priority = 101
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "49100-65535"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "bll-ephemeral-QUIC"
description = "All outbound traffic back to BLL"
priority = 102
direction = "Outbound"
access = "Allow"
protocol = "Udp"
source_port_range = "*"
destination_port_range = "49100-65535"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "ntp"
description = "NTP server"
priority = 110
direction = "Outbound"
access = "Allow"
protocol = "Udp"
source_port_range = "*"
destination_port_range = "123"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
resource "azurerm_network_security_group" "test_plane" {
name = "nsg-test-${var.instance_name}"
location = var.resource_group_location
resource_group_name = var.resource_group_name
# all traffic
security_rule {
name = "all-traffic"
priority = 100
direction = "Outbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
resource "azurerm_network_interface" "mgmt_plane" {
count = var.instance_count
name = "nic-mgmt-${var.instance_name}-${count.index}"
location = var.resource_group_location
resource_group_name = var.resource_group_name
ip_configuration {
name = "ipc-mgmt-${var.instance_name}-${count.index}"
subnet_id = var.mgmt_plane_subnet_id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = element(azurerm_public_ip.stcv.*.id, count.index)
}
}
resource "azurerm_network_interface" "test_plane" {
count = var.instance_count
name = "nic-test-${var.instance_name}-${count.index}"
location = var.resource_group_location
resource_group_name = var.resource_group_name
enable_accelerated_networking = var.enable_accelerated_networking
ip_configuration {
name = "ipc-test-${var.instance_name}-${count.index}"
subnet_id = var.test_plane_subnet_id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_network_interface_security_group_association" "mgmt_plane" {
count = var.instance_count
network_interface_id = element(azurerm_network_interface.mgmt_plane.*.id, count.index)
network_security_group_id = azurerm_network_security_group.mgmt_plane.id
}
resource "azurerm_network_interface_security_group_association" "test_plane" {
count = var.instance_count
network_interface_id = element(azurerm_network_interface.test_plane.*.id, count.index)
network_security_group_id = azurerm_network_security_group.test_plane.id
}
data "azurerm_image" "stcv" {
count = var.stcv_image_name != "" ? 1 : 0
name = var.stcv_image_name
resource_group_name = var.resource_group_name
}
# Create STCv VMs
resource "azurerm_linux_virtual_machine" "stcv" {
count = var.instance_count
name = "${var.instance_name}${count.index}"
location = var.resource_group_location
resource_group_name = var.resource_group_name
network_interface_ids = [element(azurerm_network_interface.mgmt_plane.*.id, count.index), element(azurerm_network_interface.test_plane.*.id, count.index)]
size = var.instance_size
admin_username = var.admin_username
admin_ssh_key {
username = var.admin_username
public_key = file(var.public_key)
}
custom_data = base64encode(file(var.user_data_file))
os_disk {
name = "osdisk-${var.instance_name}-${count.index}"
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_id = var.stcv_image_name != "" ? data.azurerm_image.stcv[0].id : null
dynamic "source_image_reference" {
for_each = var.stcv_image_name != "" ? [] : [1]
content {
publisher = "spirentcommunications1594084187199"
offer = "testcenter_virtual"
sku = "testcentervirtual"
version = var.marketplace_version != "" ? var.marketplace_version : "latest"
}
}
dynamic "plan" {
for_each = var.stcv_image_name != "" ? [] : [1]
content {
name = "testcentervirtual"
publisher = "spirentcommunications1594084187199"
product = "testcenter_virtual"
}
}
}