Skip to content

Commit fc11649

Browse files
Fix Azure Functions App + Service Bus Sample (#72)
1 parent d3a8eae commit fc11649

4 files changed

Lines changed: 27 additions & 16 deletions

File tree

samples/function-app-service-bus/dotnet/bicep/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ module network 'modules/virtual-network.bicep' = {
354354
functionAppSubnetName: functionAppSubnetName
355355
functionAppSubnetAddressPrefix: functionAppSubnetAddressPrefix
356356
functionAppSubnetNsgName: empty(functionAppSubnetNsgName)
357-
? toLower('${prefix}-webapp-subnet-nsg-${suffix}')
357+
? toLower('${prefix}-func-subnet-nsg-${suffix}')
358358
: functionAppSubnetNsgName
359359
peSubnetName: peSubnetName
360360
peSubnetAddressPrefix: peSubnetAddressPrefix

samples/function-app-service-bus/dotnet/terraform/main.tf

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ locals {
1111
blob_storage_private_endpoint_name = "${local.prefix}-blob-storage-pe-${local.suffix}"
1212
queue_storage_private_endpoint_name = "${local.prefix}-queue-storage-pe-${local.suffix}"
1313
table_storage_private_endpoint_name = "${local.prefix}-table-storage-pe-${local.suffix}"
14-
network_security_group_name = "${local.prefix}-default-nsg-${local.suffix}"
14+
func_subnet_nsg_name = "${local.prefix}-func-subnet-nsg-${local.suffix}"
15+
pe_subnet_nsg_name = "${local.prefix}-pe-subnet-nsg-${local.suffix}"
1516
cosmosdb_account_name = "${local.prefix}-mongodb-${local.suffix}"
1617
service_bus_namespace_name = "${local.prefix}-service-bus-${local.suffix}"
17-
app_service_plan_name = "${local.prefix}-app-service-plan-${local.suffix}"
18+
app_service_plan_name = "${local.prefix}-plan-${local.suffix}"
1819
function_app_name = "${local.prefix}-func-${local.suffix}"
1920
application_insights_name = "${local.prefix}-func-${local.suffix}"
2021
managed_identity_name = "${local.prefix}-identity-${local.suffix}"
@@ -53,8 +54,8 @@ module "virtual_network" {
5354

5455
subnets = [
5556
{
56-
name : var.webapp_subnet_name
57-
address_prefixes : var.webapp_subnet_address_prefix
57+
name : var.func_subnet_name
58+
address_prefixes : var.func_subnet_address_prefix
5859
private_endpoint_network_policies : "Enabled"
5960
private_link_service_network_policies_enabled : false
6061
delegation : "Microsoft.Web/serverFarms"
@@ -64,24 +65,34 @@ module "virtual_network" {
6465
address_prefixes : var.pe_subnet_address_prefix
6566
private_endpoint_network_policies : "Enabled"
6667
private_link_service_network_policies_enabled : false
67-
delegation : null
6868
}
6969
]
7070
}
7171

72-
# Create a network security group and associate it with both subnets
73-
module "network_security_group" {
72+
# Create a network security group and associate it with the function app subnet
73+
module "func_subnet_network_security_group" {
7474
source = "./modules/network_security_group"
75-
name = local.network_security_group_name
75+
name = local.func_subnet_nsg_name
7676
resource_group_name = azurerm_resource_group.example.name
7777
location = var.location
7878
log_analytics_workspace_id = module.log_analytics_workspace.id
7979
tags = var.tags
8080
subnet_ids = {
81-
(var.webapp_subnet_name) = module.virtual_network.subnet_ids[var.webapp_subnet_name]
82-
(var.pe_subnet_name) = module.virtual_network.subnet_ids[var.pe_subnet_name]
81+
(var.func_subnet_name) = module.virtual_network.subnet_ids[var.func_subnet_name]
8382
}
83+
}
8484

85+
# Create a network security group and associate it with the private endpoint subnet
86+
module "pe_subnet_network_security_group" {
87+
source = "./modules/network_security_group"
88+
name = local.pe_subnet_nsg_name
89+
resource_group_name = azurerm_resource_group.example.name
90+
location = var.location
91+
log_analytics_workspace_id = module.log_analytics_workspace.id
92+
tags = var.tags
93+
subnet_ids = {
94+
(var.pe_subnet_name) = module.virtual_network.subnet_ids[var.pe_subnet_name]
95+
}
8596
}
8697

8798
# Create a NAT gateway and associate it with the default subnet
@@ -94,7 +105,7 @@ module "nat_gateway" {
94105
idle_timeout_in_minutes = var.nat_gateway_idle_timeout_in_minutes
95106
zones = var.nat_gateway_zones
96107
subnet_ids = {
97-
(var.webapp_subnet_name) = module.virtual_network.subnet_ids[var.webapp_subnet_name]
108+
(var.func_subnet_name) = module.virtual_network.subnet_ids[var.func_subnet_name]
98109
}
99110
tags = var.tags
100111
}
@@ -306,7 +317,7 @@ module "function_app" {
306317
storage_account_name = module.storage_account.name
307318
storage_account_access_key = module.storage_account.primary_access_key
308319
https_only = var.https_only
309-
virtual_network_subnet_id = module.virtual_network.subnet_ids[var.webapp_subnet_name]
320+
virtual_network_subnet_id = module.virtual_network.subnet_ids[var.func_subnet_name]
310321
vnet_route_all_enabled = true
311322
public_network_access_enabled = var.public_network_access_enabled
312323
always_on = var.always_on

samples/function-app-service-bus/dotnet/terraform/modules/virtual_network/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ variable "subnets" {
2525
address_prefixes = list(string)
2626
private_endpoint_network_policies = string
2727
private_link_service_network_policies_enabled = bool
28-
delegation = string
28+
delegation = optional(string)
2929
}))
3030
}
3131

samples/function-app-service-bus/dotnet/terraform/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ variable "vnet_address_space" {
273273
type = list(string)
274274
}
275275

276-
variable "webapp_subnet_name" {
276+
variable "func_subnet_name" {
277277
description = "Specifies the name of the web app subnet."
278278
default = "app-subnet"
279279
type = string
280280
}
281281

282-
variable "webapp_subnet_address_prefix" {
282+
variable "func_subnet_address_prefix" {
283283
description = "Specifies the address prefix of the web app subnet."
284284
default = ["10.0.0.0/24"]
285285
type = list(string)

0 commit comments

Comments
 (0)