forked from Spirent-Terraform-Modules/terraform-azurerm-stcv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
175 lines (151 loc) · 6.04 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
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-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 = "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 = "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
}
# 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))
plan {
name = "testcentervirtual"
publisher = "spirentcommunications1594084187199"
product = "testcenter_virtual"
}
os_disk {
name = "osdisk-${var.instance_name}-${count.index}"
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "spirentcommunications1594084187199"
offer = "testcenter_virtual"
sku = "testcentervirtual"
version = var.marketplace_version != "" ? var.marketplace_version : "latest"
}
}