This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
forked from Azure/terraform-azurerm-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
76 lines (61 loc) · 2.83 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
#Azure Generic vNet Module
data "azurerm_resource_group" "network" {
count = var.resource_group_location == null ? 1 : 0
name = var.resource_group_name
}
locals {
resource_group_location = var.resource_group_location == null ? data.azurerm_resource_group.network[0].location : var.resource_group_location
}
resource "azurerm_virtual_network" "vnet" {
address_space = length(var.address_spaces) == 0 ? [var.address_space] : var.address_spaces
location = local.resource_group_location
name = var.vnet_name
resource_group_name = var.resource_group_name
dns_servers = var.dns_servers
tags = var.tags
}
moved {
from = azurerm_subnet.subnet
to = azurerm_subnet.subnet_count
}
resource "azurerm_subnet" "subnet_count" {
count = var.use_for_each ? 0 : length(var.subnet_names)
address_prefixes = [var.subnet_prefixes[count.index]]
name = var.subnet_names[count.index]
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.vnet.name
enforce_private_link_endpoint_network_policies = lookup(var.subnet_enforce_private_link_endpoint_network_policies, var.subnet_names[count.index], false)
service_endpoints = lookup(var.subnet_service_endpoints, var.subnet_names[count.index], [])
dynamic "delegation" {
for_each = lookup(var.subnet_delegation, var.subnet_names[count.index], [])
content {
name = delegation.value.name
service_delegation {
name = delegation.value.service_delegation.name
actions = delegation.value.service_delegation.actions
}
}
}
}
resource "azurerm_subnet" "subnet_for_each" {
for_each = var.use_for_each ? toset(var.subnet_names) : []
address_prefixes = [local.subnet_names_prefixes_map[each.value]]
name = each.value
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.vnet.name
enforce_private_link_endpoint_network_policies = lookup(var.subnet_enforce_private_link_endpoint_network_policies, each.value, false)
service_endpoints = lookup(var.subnet_service_endpoints, each.value, [])
dynamic "delegation" {
for_each = lookup(var.subnet_delegation, each.value, [])
content {
name = delegation.value.name
service_delegation {
name = delegation.value.service_delegation.name
actions = delegation.value.service_delegation.actions
}
}
}
}
locals {
azurerm_subnets = var.use_for_each ? [for s in azurerm_subnet.subnet_for_each : s] : [for s in azurerm_subnet.subnet_count : s]
}