forked from Azure/terraform-azurerm-subnets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
83 lines (66 loc) · 3.26 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
resource "azurerm_virtual_network" "vnet" {
address_space = var.virtual_network_address_space
location = var.virtual_network_location
name = var.virtual_network_name
resource_group_name = var.resource_group_name
bgp_community = var.virtual_network_bgp_community
edge_zone = var.virtual_network_edge_zone
flow_timeout_in_minutes = var.virtual_network_flow_timeout_in_minutes
tags = var.virtual_network_tags
dynamic "ddos_protection_plan" {
for_each = var.virtual_network_ddos_protection_plan != null ? [var.virtual_network_ddos_protection_plan] : []
content {
enable = ddos_protection_plan.value.enable
id = ddos_protection_plan.value.id
}
}
}
resource "azurerm_virtual_network_dns_servers" "vnet_dns" {
count = var.virtual_network_dns_servers == null ? 0 : 1
virtual_network_id = azurerm_virtual_network.vnet.id
dns_servers = var.virtual_network_dns_servers.dns_servers
}
resource "azurerm_subnet" "subnet" {
for_each = local.subnet_names
address_prefixes = var.subnets[each.value].address_prefixes
name = each.value
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.vnet.name
private_endpoint_network_policies_enabled = var.subnets[each.value].private_endpoint_network_policies_enabled
private_link_service_network_policies_enabled = var.subnets[each.value].private_link_service_network_policies_enabled
service_endpoint_policy_ids = var.subnets[each.value].service_endpoint_policy_ids
service_endpoints = var.subnets[each.value].service_endpoints
dynamic "delegation" {
for_each = var.subnets[each.value].delegations == null ? [] : var.subnets[each.value].delegations
content {
name = delegation.value.name
service_delegation {
name = delegation.value.service_delegation.name
actions = delegation.value.service_delegation.actions
}
}
}
# Do not remove this `depends_on` or we'll met a parallel related issue that failed the creation of `azurerm_subnet_route_table_association` and `azurerm_subnet_network_security_group_association`
depends_on = [azurerm_virtual_network_dns_servers.vnet_dns]
}
locals {
azurerm_subnet_name2id = {
for index, subnet in azurerm_subnet.subnet :
subnet.name => subnet.id
}
}
resource "azurerm_subnet_network_security_group_association" "vnet" {
for_each = toset(local.subnet_names_with_network_security_group)
network_security_group_id = var.subnets[each.value].network_security_group.id
subnet_id = local.azurerm_subnet_name2id[each.value]
}
resource "azurerm_subnet_route_table_association" "vnet" {
for_each = toset(local.subnet_names_with_route_table)
route_table_id = var.subnets[each.value].route_table.id
subnet_id = local.azurerm_subnet_name2id[each.value]
}
resource "azurerm_subnet_nat_gateway_association" "nat_gw" {
for_each = toset(local.subnet_names_with_nat_gateway)
nat_gateway_id = var.subnets[each.value].nat_gateway.id
subnet_id = local.azurerm_subnet_name2id[each.value]
}