Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 918c3d6

Browse files
stanleyzlonegunmanb
authored andcommitted
Add support for service delegation and example code
1 parent f987451 commit 918c3d6

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

main.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ resource "azurerm_subnet" "subnet" {
2323
enforce_private_link_service_network_policies = lookup(var.subnet_enforce_private_link_service_network_policies, var.subnet_names[count.index], false)
2424

2525
dynamic "delegation" {
26-
for_each = lookup(var.subnet_delegation, var_subnet_names[count.index], {})
27-
name = lookup(delegation.value, "name")
28-
service_delegation {
29-
name = lookup(delegation.value, "service_name")
30-
actions = lookup(delegation.value, "service_actions", [])
26+
for_each = lookup(var.subnet_delegation, var.subnet_names[count.index], {})
27+
content {
28+
name = delegation.key
29+
service_delegation {
30+
name = lookup(delegation.value, "service_name")
31+
actions = lookup(delegation.value, "service_actions", [])
32+
}
3133
}
3234
}
3335
}

test/fixture/main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ module "vnet" {
4040
subnet3 = ["Microsoft.AzureActiveDirectory"]
4141
}
4242

43+
subnet_delegation = {
44+
subnet2 = {
45+
"Microsoft.Sql.managedInstances" = {
46+
service_name = "Microsoft.Sql/managedInstances"
47+
service_actions = [
48+
"Microsoft.Network/virtualNetworks/subnets/join/action",
49+
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
50+
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action",
51+
]
52+
}
53+
}
54+
}
55+
4356
route_tables_ids = {
4457
subnet1 = azurerm_route_table.rt1.id
4558
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ variable "subnet_enforce_private_link_service_network_policies" {
5252
default = {}
5353
}
5454

55+
variable "subnet_delegation" {
56+
description = "A map of subnet name to delegation block on the subnet"
57+
type = map(map(any))
58+
default = {}
59+
}
60+
5561
variable "nsg_ids" {
5662
description = "A map of subnet name to Network Security Group IDs"
5763
type = map(string)

0 commit comments

Comments
 (0)