forked from Azure/terraform-azurerm-vnet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
55 lines (48 loc) · 2.27 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
#Azure Generic vNet Module
data azurerm_resource_group "vnet" {
name = var.resource_group_name
}
resource azurerm_virtual_network "vnet" {
name = var.vnet_name
resource_group_name = data.azurerm_resource_group.vnet.name
location = var.vnet_location != null ? var.vnet_location : data.azurerm_resource_group.vnet.location
address_space = var.address_space
dns_servers = var.dns_servers
tags = var.tags
}
resource "azurerm_subnet" "subnet" {
count = length(var.subnet_names)
name = var.subnet_names[count.index]
resource_group_name = data.azurerm_resource_group.vnet.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = [var.subnet_prefixes[count.index]]
service_endpoints = lookup(var.subnet_service_endpoints, var.subnet_names[count.index], null)
enforce_private_link_endpoint_network_policies = lookup(var.subnet_enforce_private_link_endpoint_network_policies, var.subnet_names[count.index], false)
enforce_private_link_service_network_policies = lookup(var.subnet_enforce_private_link_service_network_policies, var.subnet_names[count.index], false)
dynamic "delegation" {
for_each = lookup(var.delegation_name, var.subnet_names[count.index], null) == null ? []:[1]
content {
name = lookup(var.delegation_name, var.subnet_names[count.index], null)
service_delegation {
name = lookup(var.service_delegation_name, var.subnet_names[count.index], null)
actions = lookup(var.service_delegation_actions, var.subnet_names[count.index], null)
}
}
}
}
locals {
azurerm_subnets = {
for index, subnet in azurerm_subnet.subnet :
subnet.name => subnet.id
}
}
resource "azurerm_subnet_network_security_group_association" "vnet" {
for_each = var.nsg_ids
subnet_id = local.azurerm_subnets[each.key]
network_security_group_id = each.value
}
resource "azurerm_subnet_route_table_association" "vnet" {
for_each = var.route_tables_ids
route_table_id = each.value
subnet_id = local.azurerm_subnets[each.key]
}