Skip to content

Commit 24f9d6c

Browse files
committed
be able to use different resource group for hub network
1 parent 3666dfc commit 24f9d6c

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

azure/infrastructure.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module "network_hub" {
7878
deployment_name = lower(local.deployment_name)
7979
az_region = var.az_region
8080
resource_group_name = local.resource_group_name
81+
resource_group_hub_name = var.resource_group_hub_name
8182
vnet_name = var.vnet_hub_name
8283
vnet_address_range = var.vnet_hub_address_range
8384
subnet_gateway_name = var.subnet_hub_gateway_name

azure/modules/network_spoke/infrastructure.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ data "azurerm_subnet" "subnet-spoke-workload" {
2222
}
2323

2424
locals {
25-
vnet_hub_id = format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s", data.azurerm_subscription.current.subscription_id, var.resource_group_name, var.vnet_hub_name)
25+
vnet_hub_id = format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s", data.azurerm_subscription.current.subscription_id, local.resource_group_hub_name, var.vnet_hub_name)
2626
vnet_name = var.vnet_name == "" ? azurerm_virtual_network.vnet-spoke.0.name : var.vnet_name
2727
# subnet_mgmt_name = var.subnet_mgmt_name == "" ? azurerm_subnet.subnet-spoke-mgmt.0.name : var.vnet_name
2828
# subnet_mgmt_id = var.subnet_mgmt_name == "" ? azurerm_subnet.subnet-spoke-mgmt.0.id : format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", data.azurerm_subscription.current.subscription_id, var.resource_group_name, var.vnet_name, var.subnet_mgmt_name)
2929
subnet_workload_name = var.subnet_workload_name == "" ? azurerm_subnet.subnet-spoke-workload.0.name : var.vnet_name
3030
subnet_workload_id = var.subnet_workload_name == "" ? azurerm_subnet.subnet-spoke-workload.0.id : format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", data.azurerm_subscription.current.subscription_id, var.resource_group_name, var.vnet_name, var.subnet_workload_name)
31+
resource_group_hub_name = var.resource_group_hub_name == "" ? var.resource_group_name : var.resource_group_hub_name
3132
}
3233

3334
# Network resources: Virtual Network, Subnet

azure/modules/network_spoke/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ variable "resource_group_name" {
1919
type = string
2020
}
2121

22+
variable "resource_group_hub_name" {
23+
description = "Already existing resource group where the Hub infrastructure was created. If it's not set the resource_group_name is used instead."
24+
type = string
25+
}
26+
2227
variable "vnet_hub_name" {
2328
description = "Already existing virtual network name used by the created infrastructure. If it's not set a new one will be created named vnet-{{var.deployment_name/terraform.workspace}}"
2429
type = string

azure/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ variable "resource_group_name" {
1212
default = ""
1313
}
1414

15+
variable "resource_group_hub_name" {
16+
description = "Already existing resource group where the Hub infrastructure was created. If it's not set the resource_group_name is used instead."
17+
type = string
18+
default = ""
19+
}
20+
1521
variable "vnet_name" {
1622
description = "Already existing virtual network name used by the created infrastructure. If it's not set a new one will be created named vnet-{{var.deployment_name/terraform.workspace}}"
1723
type = string

0 commit comments

Comments
 (0)