Skip to content

Commit 08f0db8

Browse files
authored
Feat/dtoss 9003 deploy service bus into the hub vnet (#176)
* DTOSS: Fix the name of the ACR * DTOSS-9003: Deploy service bus into the hub vnet * DTOSS-9006: Update the Service Bus module cause it must have private end points to work * DTOSS-9006: Update the Service Bus module cause it must have private end points to work * DTOSS-9006: Update the Service Bus module cause it must have private end points to work * DTOSS-9006: Update the Service Bus module cause it must have private end points to work
1 parent c6c4b4b commit 08f0db8

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

infrastructure/modules/service-bus/example/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ module "azure_service_bus" {
1111
capacity = each.value.capacity
1212
sku_tier = each.value.sku_tier
1313

14+
# Private Endpoint Configuration if enabled
15+
private_endpoint_properties = var.features.private_endpoints_enabled ? {
16+
# THIS MUST be changed to service bus
17+
private_dns_zone_ids = [data.terraform_remote_state.hub.outputs.private_dns_zones["${each.value.region}-event_hub"].id]
18+
private_endpoint_enabled = var.features.private_endpoints_enabled
19+
private_endpoint_subnet_id = module.subnets["${module.regions_config[each.value.region].names.subnet}-pep"].id
20+
private_endpoint_resource_group_name = azurerm_resource_group.rg_private_endpoints[each.value.region].name
21+
private_service_connection_is_manual = var.features.private_service_connection_is_manual
22+
} : null
23+
24+
1425
tags = var.tags
1526
}
1627

infrastructure/modules/service-bus/example/variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ variable "regions" {
1515
}))
1616
}
1717

18+
variable "private_endpoint_properties" {
19+
description = "Consolidated properties for the Service Bus Private Endpoint."
20+
type = object({
21+
private_dns_zone_ids = optional(list(string), [])
22+
private_endpoint_enabled = optional(bool, false)
23+
private_endpoint_subnet_id = optional(string, "")
24+
private_endpoint_resource_group_name = optional(string, "")
25+
private_service_connection_is_manual = optional(bool, false)
26+
})
27+
28+
validation {
29+
condition = (
30+
can(var.private_endpoint_properties == null) ||
31+
can(var.private_endpoint_properties.private_endpoint_enabled == false) ||
32+
can((length(var.private_endpoint_properties.private_dns_zone_ids) > 0 &&
33+
length(var.private_endpoint_properties.private_endpoint_subnet_id) > 0
34+
)
35+
)
36+
)
37+
error_message = "Both private_dns_zone_ids and private_endpoint_subnet_id must be provided if private_endpoint_enabled is true."
38+
}
39+
}
40+
1841
variable "service_bus" {
1942
description = "Configuration for Service Bus namespaces and their topics"
2043
type = map(object({

infrastructure/modules/service-bus/main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,37 @@ resource "azurerm_servicebus_topic" "this" {
2727
status = each.value.status
2828
}
2929

30+
resource "azurerm_servicebus_namespace_authorization_rule" "this" {
31+
name = "access-rule"
32+
namespace_id = azurerm_servicebus_namespace.this.id
33+
34+
listen = true
35+
send = true
36+
manage = false
37+
}
38+
39+
40+
module "private_endpoint_service_bus_namespace" {
41+
count = var.private_endpoint_properties.private_endpoint_enabled ? 1 : 0
42+
43+
source = "../private-endpoint"
44+
45+
name = "${var.servicebus_namespace_name}-servicebus-private-endpoint"
46+
resource_group_name = var.private_endpoint_properties.private_endpoint_resource_group_name
47+
location = var.location
48+
subnet_id = var.private_endpoint_properties.private_endpoint_subnet_id
49+
50+
private_dns_zone_group = {
51+
name = "${var.servicebus_namespace_name}-private-endpoint-zone-group"
52+
private_dns_zone_ids = var.private_endpoint_properties.private_dns_zone_ids
53+
}
54+
55+
private_service_connection = {
56+
name = "${var.servicebus_namespace_name}-private-endpoint-connection"
57+
private_connection_resource_id = azurerm_servicebus_namespace.this.id
58+
subresource_names = ["namespace"]
59+
is_manual_connection = var.private_endpoint_properties.private_service_connection_is_manual
60+
}
61+
62+
tags = var.tags
63+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
output "servicebus_connection_string" {
2+
value = azurerm_servicebus_namespace_authorization_rule.this.primary_connection_string
3+
sensitive = true
4+
}
5+
6+
output "namespace_id" {
7+
value = azurerm_servicebus_namespace.this.id
8+
}

infrastructure/modules/service-bus/variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,25 @@ variable "tags" {
8989
default = {}
9090
}
9191

92+
variable "private_endpoint_properties" {
93+
description = "Consolidated properties for the Service Bus Private Endpoint."
94+
type = object({
95+
private_dns_zone_ids = optional(list(string), [])
96+
private_endpoint_enabled = optional(bool, false)
97+
private_endpoint_subnet_id = optional(string, "")
98+
private_endpoint_resource_group_name = optional(string, "")
99+
private_service_connection_is_manual = optional(bool, false)
100+
})
101+
102+
validation {
103+
condition = (
104+
can(var.private_endpoint_properties == null) ||
105+
can(var.private_endpoint_properties.private_endpoint_enabled == false) ||
106+
can((length(var.private_endpoint_properties.private_dns_zone_ids) > 0 &&
107+
length(var.private_endpoint_properties.private_endpoint_subnet_id) > 0
108+
)
109+
)
110+
)
111+
error_message = "Both private_dns_zone_ids and private_endpoint_subnet_id must be provided if private_endpoint_enabled is true."
112+
}
113+
}

0 commit comments

Comments
 (0)