-
Notifications
You must be signed in to change notification settings - Fork 133
/
vnet.tf
99 lines (84 loc) · 3.48 KB
/
vnet.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
resource "azurerm_virtual_network" "this" {
name = "${local.prefix}-vnet"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
address_space = [local.cidr]
tags = local.tags
}
resource "azurerm_network_security_group" "this" {
name = "${local.prefix}-nsg"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
tags = local.tags
}
resource "azurerm_subnet" "public" {
name = "${local.prefix}-public"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [cidrsubnet(local.cidr, 3, 0)]
delegation {
name = "databricks"
service_delegation {
name = "Microsoft.Databricks/workspaces"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action",
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"]
}
}
}
resource "azurerm_subnet_network_security_group_association" "public" {
subnet_id = azurerm_subnet.public.id
network_security_group_id = azurerm_network_security_group.this.id
}
variable "private_subnet_endpoints" {
default = []
}
resource "azurerm_subnet" "private" {
name = "${local.prefix}-private"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [cidrsubnet(local.cidr, 3, 1)]
delegation {
name = "databricks"
service_delegation {
name = "Microsoft.Databricks/workspaces"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action",
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"]
}
}
service_endpoints = var.private_subnet_endpoints
}
resource "azurerm_subnet_network_security_group_association" "private" {
subnet_id = azurerm_subnet.private.id
network_security_group_id = azurerm_network_security_group.this.id
}
resource "azurerm_virtual_network" "hubvnet" {
name = "${local.prefix}-hub-vnet"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
address_space = [var.hubcidr]
tags = local.tags
}
resource "azurerm_subnet" "hubfw" {
//name must be fixed as AzureFirewallSubnet
name = "AzureFirewallSubnet"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.hubvnet.name
address_prefixes = [cidrsubnet(var.hubcidr, 3, 0)]
service_endpoints = ["Microsoft.Storage"]
}
resource "azurerm_virtual_network_peering" "hubvnet" {
name = "peerhubtospoke"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.hubvnet.name
remote_virtual_network_id = azurerm_virtual_network.this.id
}
resource "azurerm_virtual_network_peering" "spokevnet" {
name = "peerspoketohub"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
remote_virtual_network_id = azurerm_virtual_network.hubvnet.id
}