-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnics.tf
134 lines (120 loc) · 6.65 KB
/
nics.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
# Create the public IP address
resource "azurerm_public_ip" "pip" {
count = var.specs[terraform.workspace]["instance_count"]
name = "pip-${count.index}-mgmt"
location = azurerm_resource_group.azmain.location
resource_group_name = azurerm_resource_group.azmain.name
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
domain_name_label = "${var.specs[terraform.workspace]["fqdn_name"]}${count.index}"
#domain_name_label = var.specs[terraform.workspace]["fqdn_name"]
zones = [element(local.azs, count.index)]
}
resource "azurerm_public_ip" "untrust_pip" {
depends_on = [azurerm_virtual_network.virtual_net]
count = var.specs[terraform.workspace]["instance_count"]
name = "pip-${count.index}-Untrust"
location = azurerm_resource_group.azmain.location
resource_group_name = azurerm_resource_group.azmain.name
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
zones = [element(local.azs, count.index)]
}
resource "azurerm_public_ip" "untrust_pip_sec" {
depends_on = [azurerm_virtual_network.virtual_net]
count = var.specs[terraform.workspace]["instance_count"]
name = "pip-${count.index}-Untrust_sec"
location = azurerm_resource_group.azmain.location
resource_group_name = azurerm_resource_group.azmain.name
allocation_method = "Static" # Static is required due to the use of the Standard sku
sku = "Standard" # the Standard sku is required due to the use of availability zones
zones = [element(local.azs, count.index)]
}
data "azurerm_public_ip" "untrust_pip_sec" {
count = var.specs[terraform.workspace]["instance_count"]
depends_on = [azurerm_virtual_network.virtual_net]
name = azurerm_public_ip.untrust_pip_sec[count.index].name
resource_group_name = azurerm_linux_virtual_machine.virtualmachine[count.index].resource_group_name
zones = [element(local.azs, count.index)]
}
# data "azurerm_network_interface" "Untrust" {
# count = var.specs[terraform.workspace]["instance_count"]
# depends_on = [azurerm_virtual_network.virtual_net]
# name = azurerm_network_interface.Untrust[count.index].name
# resource_group_name = azurerm_linux_virtual_machine.virtualmachine[count.index].resource_group_name
# zones = [element(local.azs, count.index)]
# }
#
# Create the network interfaces
resource "azurerm_network_interface" "Management" {
depends_on = [azurerm_virtual_network.virtual_net]
count = var.specs[terraform.workspace]["instance_count"]
name = "nic-${count.index}-mgmt"
location = azurerm_resource_group.azmain.location
resource_group_name = azurerm_resource_group.azmain.name
ip_configuration {
name = "mgmt-${count.index}-ip-0"
subnet_id = azurerm_subnet.Management[count.index % length(local.azs)].id
private_ip_address_allocation = "dynamic"
public_ip_address_id = element(azurerm_public_ip.pip.*.id, count.index)
primary = "true"
}
}
# Create the network interfaces
resource "azurerm_network_interface" "Untrust" {
depends_on = [azurerm_virtual_network.virtual_net]
count = var.specs[terraform.workspace]["instance_count"]
name = "nic-${count.index}-untrust"
location = azurerm_resource_group.azmain.location
resource_group_name = azurerm_resource_group.azmain.name
enable_ip_forwarding = true
# this option enable_accelerated_networking will only work with specific Images version. DS4 is one of them
enable_accelerated_networking = true
ip_configuration {
name = "untrust-${count.index}-ip-0"
subnet_id = azurerm_subnet.Untrust[count.index % length(local.azs)].id
private_ip_address_allocation = "dynamic"
#private_ip_address_allocation = "Static"
#private_ip_address = var.specs[terraform.workspace]["static_ip"][1]
#private_ip_address = var.specs[terraform.workspace]["static_ip"]
public_ip_address_id = azurerm_public_ip.untrust_pip[count.index].id
primary = true
}
ip_configuration {
name = "untrust-${count.index}-ip-1"
subnet_id = azurerm_subnet.Untrust[count.index % length(local.azs)].id
private_ip_address_allocation = "dynamic"
#private_ip_address_allocation = "Static"
# private_ip_address = var.specs[terraform.workspace]["static_sec_ip"][1]
#private_ip_address = var.specs[terraform.workspace]["static_sec_ip"]
public_ip_address_id = azurerm_public_ip.untrust_pip_sec[count.index].id
}
}
# Create the network interfaces
resource "azurerm_network_interface" "Trust" {
depends_on = [azurerm_virtual_network.virtual_net]
count = var.specs[terraform.workspace]["instance_count"]
name = "nic-${count.index}-trust"
location = azurerm_resource_group.azmain.location
resource_group_name = azurerm_resource_group.azmain.name
enable_ip_forwarding = true
enable_accelerated_networking = true
ip_configuration {
name = "nic-${count.index}-ip-0"
subnet_id = azurerm_subnet.Trust[count.index % length(local.azs)].id
private_ip_address_allocation = "dynamic"
# private_ip_address = var.specs[terraform.workspace]["static_ip"][0]
}
}
# Connect the security group to the network interface
resource "azurerm_network_interface_security_group_association" "jointogether_networks" {
count = var.specs[terraform.workspace]["instance_count"]
network_interface_id = element(azurerm_network_interface.Management.*.id, count.index)
network_security_group_id = element(azurerm_network_security_group.security_gr.*.id, count.index)
}
# Untrust Network
resource "azurerm_network_interface_security_group_association" "Untrust-security" {
count = var.specs[terraform.workspace]["instance_count"]
network_interface_id = azurerm_network_interface.Untrust[count.index].id
network_security_group_id = azurerm_network_security_group.application_sg[count.index].id
}