-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
220 lines (220 loc) · 9.63 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
terraform {
required_version = ">=0.12.17"
}
provider "azurerm" {
version = ">=2.0.0"
features {
virtual_machine {
delete_os_disk_on_deletion = "true"
}
}
}
resource "azurerm_resource_group" "poc_resourcegroup" {
name = var.resourcegroup_name
location = var.resourcegroup_location
}
resource azurerm_virtual_network "poc_virtualnetwork" {
name = "${var.resourcegroup_name}_vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.poc_resourcegroup.location
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
}
resource azurerm_subnet "webtier_subnet" {
name = "webtier_subnet"
address_prefix = "10.0.1.0/24"
virtual_network_name = azurerm_virtual_network.poc_virtualnetwork.name
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
}
resource "azurerm_public_ip" "webtier_publicips" {
count = length(var.webtiervms_name)
name = "${element(var.webtiervms_name, count.index)}-ip"
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
location = azurerm_resource_group.poc_resourcegroup.location
allocation_method = "Static"
}
resource "azurerm_network_security_group" "webtier_nsg" {
name = "webtier_nsg"
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
location = azurerm_resource_group.poc_resourcegroup.location
dynamic "security_rule" {
for_each = var.webtier_security_rules
content {
name = security_rule.value.rule_name
priority = security_rule.value.priority
direction = security_rule.value.direction
access = security_rule.value.access
protocol = security_rule.value.protocol
source_port_range = security_rule.value.source_port_range
destination_port_range = security_rule.value.destination_port_range
source_address_prefix = security_rule.value.source_address_prefix
destination_address_prefix = security_rule.value.destination_address_prefix
}
}
}
resource "azurerm_network_interface_security_group_association" "webtier_nic_nsg_association" {
count = length(var.webtiervms_name)
network_interface_id = azurerm_network_interface.webtier_nics[count.index].id
network_security_group_id = azurerm_network_security_group.webtier_nsg.id
}
resource "azurerm_network_interface" "webtier_nics" {
count = length(var.webtiervms_name)
name = "${element(var.webtiervms_name, count.index)}-nic"
ip_configuration {
name = "ip_configuration"
private_ip_address_allocation = "Dynamic"
subnet_id = azurerm_subnet.webtier_subnet.id
public_ip_address_id = azurerm_public_ip.webtier_publicips[count.index].id
}
location = azurerm_resource_group.poc_resourcegroup.location
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
}
resource "azurerm_windows_virtual_machine" "webtier_vms" {
count = length(var.webtiervms_name)
name = element(var.webtiervms_name, count.index)
location = azurerm_resource_group.poc_resourcegroup.location
admin_password = var.webtier_vms_admin_password
admin_username = var.webtier_vms_admin_username
network_interface_ids = [
azurerm_network_interface.webtier_nics[count.index].id
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
size = var.webtier_vms_size
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}
resource azurerm_subnet "apptier_subnet" {
name = "apptier_subnet"
address_prefix = "10.0.2.0/24"
virtual_network_name = azurerm_virtual_network.poc_virtualnetwork.name
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
}
resource "azurerm_network_security_group" "apptier_nsg" {
name = "apptier_nsg"
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
location = azurerm_resource_group.poc_resourcegroup.location
dynamic "security_rule" {
for_each = var.apptier_security_rules
content {
name = security_rule.value.rule_name
priority = security_rule.value.priority
direction = security_rule.value.direction
access = security_rule.value.access
protocol = security_rule.value.protocol
source_port_range = security_rule.value.source_port_range
destination_port_range = security_rule.value.destination_port_range
source_address_prefix = security_rule.value.source_address_prefix
destination_address_prefix = security_rule.value.destination_address_prefix
}
}
}
resource "azurerm_network_interface_security_group_association" "apptier_nic_nsg_association" {
count = length(var.apptiervms_name)
network_interface_id = azurerm_network_interface.apptier_nics[count.index].id
network_security_group_id = azurerm_network_security_group.apptier_nsg.id
}
resource "azurerm_network_interface" "apptier_nics" {
count = length(var.apptiervms_name)
name = "${element(var.apptiervms_name, count.index)}-nic"
ip_configuration {
name = "ip_configuration"
private_ip_address_allocation = "Dynamic"
subnet_id = azurerm_subnet.apptier_subnet.id
# public_ip_address_id = azurerm_public_ip.webtier_publicips[count.index].id
}
location = azurerm_resource_group.poc_resourcegroup.location
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
}
resource "azurerm_windows_virtual_machine" "apptier_vms" {
count = length(var.apptiervms_name)
name = element(var.apptiervms_name, count.index)
location = azurerm_resource_group.poc_resourcegroup.location
admin_password = var.apptier_vms_admin_password
admin_username = var.apptier_vms_admin_username
network_interface_ids = [
azurerm_network_interface.apptier_nics[count.index].id
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
size = var.apptier_vms_size
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}
resource azurerm_subnet "databasetier_subnet" {
name = "databasetier_subnet"
address_prefix = "10.0.3.0/24"
virtual_network_name = azurerm_virtual_network.poc_virtualnetwork.name
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
}
resource "azurerm_network_security_group" "databasetier_nsg" {
name = "databasetier_nsg"
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
location = azurerm_resource_group.poc_resourcegroup.location
dynamic "security_rule" {
for_each = var.databasetier_security_rules
content {
name = security_rule.value.rule_name
priority = security_rule.value.priority
direction = security_rule.value.direction
access = security_rule.value.access
protocol = security_rule.value.protocol
source_port_range = security_rule.value.source_port_range
destination_port_range = security_rule.value.destination_port_range
source_address_prefix = security_rule.value.source_address_prefix
destination_address_prefix = security_rule.value.destination_address_prefix
}
}
}
resource "azurerm_network_interface_security_group_association" "databasetier_nic_nsg_association" {
count = length(var.databasetiervms_name)
network_interface_id = azurerm_network_interface.databasetier_nics[count.index].id
network_security_group_id = azurerm_network_security_group.databasetier_nsg.id
}
resource "azurerm_network_interface" "databasetier_nics" {
count = length(var.databasetiervms_name)
name = "${element(var.databasetiervms_name, count.index)}-nic"
ip_configuration {
name = "ip_configuration"
private_ip_address_allocation = "Dynamic"
subnet_id = azurerm_subnet.apptier_subnet.id
# public_ip_address_id = azurerm_public_ip.webtier_publicips[count.index].id
}
location = azurerm_resource_group.poc_resourcegroup.location
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
}
resource "azurerm_windows_virtual_machine" "databasetier_vms" {
count = length(var.databasetiervms_name)
name = element(var.databasetiervms_name, count.index)
location = azurerm_resource_group.poc_resourcegroup.location
admin_password = var.databasetier_vms_admin_password
admin_username = var.databasetier_vms_admin_username
network_interface_ids = [
azurerm_network_interface.databasetier_nics[count.index].id
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
resource_group_name = azurerm_resource_group.poc_resourcegroup.name
size = var.databasetier_vms_size
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}