-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
41 lines (34 loc) · 1.69 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
locals {
virtual_network_name = var.create_virtual_network ? azurerm_virtual_network.principal[0].name : data.azurerm_virtual_network.principal[0].name
virtual_network_address_space = var.create_virtual_network ? azurerm_virtual_network.principal[0].address_space : data.azurerm_virtual_network.principal[0].address_space
}
data "azurerm_virtual_network" "principal" {
count = var.create_virtual_network ? 0 : 1
name = var.virtual_network_name
resource_group_name = var.resource_group_name
}
resource "azurerm_virtual_network" "principal" {
count = var.create_virtual_network ? 1 : 0
name = var.virtual_network_name
location = var.virtual_network_location
resource_group_name = var.resource_group_name
address_space = var.virtual_network_address_space
}
resource "azurerm_subnet" "principal_public" {
name = "${var.subnet_name_prefix}-public"
resource_group_name = var.resource_group_name
virtual_network_name = local.virtual_network_name
address_prefixes = [cidrsubnet(one(local.virtual_network_address_space), 8, 10)]
}
resource "azurerm_subnet" "principal_private" {
name = "${var.subnet_name_prefix}-private"
resource_group_name = var.resource_group_name
virtual_network_name = local.virtual_network_name
address_prefixes = [cidrsubnet(one(local.virtual_network_address_space), 8, 11)]
}
resource "azurerm_subnet" "principal_database" {
name = "${var.subnet_name_prefix}-database"
resource_group_name = var.resource_group_name
virtual_network_name = local.virtual_network_name
address_prefixes = [cidrsubnet(one(local.virtual_network_address_space), 8, 20)]
}