Skip to content

Commit bf80e2c

Browse files
dnks0claude
andauthored
feat: add networking_resource_group variable for Azure module (#6)
Allow users to specify a separate resource group for existing VNet/subnet lookups, enabling scenarios where networking and proxy resources live in different resource groups. Defaults to resource_group when not set. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5839651 commit bf80e2c

7 files changed

Lines changed: 35 additions & 15 deletions

File tree

terraform/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The module supports two modes:
1717

1818
- **`bootstrap`** (default)
1919
- Creates and configures an internal load balancer, a private endpoint service and the proxy compute.
20-
- If networking (VPC/VNet & subnets) **are provided** along with `resource_group`, the module uses existing networking.
20+
- If networking (VPC/VNet & subnets) **are provided** along with `resource_group` or `networking_resource_group` (Azure), the module uses existing networking. Use `networking_resource_group` when the VNet/subnet reside in a different resource group than the proxy resources.
2121
- If networking is **not provided**, the module creates the necessary networking resources (including a new resource group if `resource_group` is `null`).
2222

2323
- **`proxy-only`**

terraform/azure/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ module "dbx_proxy" {
2424
2525
# Azure config
2626
location = "westeurope"
27-
resource_group = "rg-dbx-proxy" # optional in bootstrap mode (required when using existing networking)
27+
resource_group = "rg-dbx-proxy" # optional in bootstrap mode
28+
# networking_resource_group = "rg-networking" # optional, defaults to resource_group. Set if VNet/subnet live in a different RG.
2829
tags = {}
2930
3031
# dbx-proxy config
@@ -52,7 +53,8 @@ After apply, use the output `load_balancer.private_link_service_alias` when crea
5253
| Variable | Type | Default | Description |
5354
|---|---:|---:|---|
5455
| `location` | `string` | (required) | Azure region to deploy to. |
55-
| `resource_group` | `string` | `null` | Resource group name. Required when using existing networking (`vnet_name`/`subnet_name`) or in `proxy-only` mode. If `null` in `bootstrap`, a new one is created. |
56+
| `resource_group` | `string` | `null` | Resource group name for proxy resources. Required in `proxy-only` mode. If `null` in `bootstrap`, a new one is created. |
57+
| `networking_resource_group` | `string` | `null` | Resource group where the existing VNet/subnet reside. Defaults to `resource_group` if not set. Required (or `resource_group`) when using existing networking. |
5658
| `vnet_name` | `string` | `null` | Existing VNet name. If `null` in `bootstrap`, a new VNet is created. |
5759
| `subnet_name` | `string` | `null` | Existing subnet name. If empty in `bootstrap`, a new subnet is created. |
5860
| `vnet_cidr` | `string` | `"10.0.0.0/16"` | VNet CIDR (only used when bootstrapping). |
@@ -94,6 +96,6 @@ Common variables are documented in `terraform/README.md`.
9496

9597
### Notes for Azure users
9698

97-
- `resource_group` is required when using existing networking (`vnet_name`/`subnet_name`), as it is used to look up the VNet and subnet. If `null` in `bootstrap` mode (without existing networking), a new one is created.
99+
- When using existing networking (`vnet_name`/`subnet_name`), either `resource_group` or `networking_resource_group` must be set for the VNet/subnet lookup. Use `networking_resource_group` when the networking lives in a different resource group than the proxy resources. If `resource_group` is `null` in `bootstrap` mode, a new one is created for the proxy resources.
98100
- Multi availability-zone resilience requires a zonal region and `min_capacity >= 2`; the VM scale set balances VMs over the available zones.
99101
- In Azure a subnet spans multiple availability-zones, therefore a single subnet is sufficient. In `proxy-only` mode, you are responsible to provide a subnet. In `bootstrap` mode, a default subnet is created.

terraform/azure/local.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ locals {
1919
: data.azurerm_resource_group.this[0].name
2020
)
2121

22+
networking_resource_group = (
23+
var.networking_resource_group != null
24+
? var.networking_resource_group
25+
: local.resource_group
26+
)
27+
2228
subnet_name = module.networking.subnet_name
2329
subnet_id = module.networking.subnet_id
2430
subnet_cidr = module.networking.subnet_cidr

terraform/azure/main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ module "networking" {
1717

1818
bootstrap_networking = local.bootstrap_networking
1919

20-
prefix = local.prefix
21-
location = var.location
22-
resource_group = local.resource_group
23-
tags = local.tags
20+
prefix = local.prefix
21+
location = var.location
22+
resource_group = local.resource_group
23+
networking_resource_group = local.networking_resource_group
24+
tags = local.tags
2425

2526
vnet_name = var.vnet_name
2627
vnet_cidr = var.vnet_cidr
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
data "azurerm_subnet" "this" {
22
count = var.bootstrap_networking ? 0 : 1
33
name = var.subnet_name
4-
resource_group_name = var.resource_group
4+
resource_group_name = var.networking_resource_group
55
virtual_network_name = var.vnet_name
66
}

terraform/azure/modules/networking/variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ variable "location" {
99
}
1010

1111
variable "resource_group" {
12-
description = "Resource group name."
12+
description = "Resource group name for bootstrapped networking resources."
13+
type = string
14+
}
15+
16+
variable "networking_resource_group" {
17+
description = "Resource group name where the existing VNet and subnet reside. Used for data source lookups when not bootstrapping."
1318
type = string
1419
}
1520

terraform/azure/variables.tf

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ variable "location" {
1111

1212
variable "resource_group" {
1313
type = string
14-
description = "Resource group name. Required when using existing networking (vnet_name/subnet_name) or in proxy-only mode. If null in bootstrap mode, a new resource group is created."
14+
description = "Resource group name for proxy resources. Required in proxy-only mode. If null in bootstrap mode, a new resource group is created."
15+
default = null
16+
}
17+
18+
variable "networking_resource_group" {
19+
type = string
20+
description = "Resource group name where the existing VNet and subnet reside. Required when using existing networking (vnet_name/subnet_name) and the networking lives in a different resource group. Defaults to resource_group if not set."
1521
default = null
1622
}
1723

@@ -51,16 +57,16 @@ variable "deployment_mode" {
5157
}
5258

5359
variable "vnet_name" {
54-
description = "Name of existing VNet. If null in bootstrap mode, a new VNet is created. Requires resource_group to be set."
60+
description = "Name of existing VNet. If null in bootstrap mode, a new VNet is created. Requires resource_group or networking_resource_group to be set."
5561
type = string
5662
default = null
5763
validation {
5864
condition = var.vnet_name == null || var.subnet_name != null
5965
error_message = "When vnet_name is set, subnet_name must also be provided."
6066
}
6167
validation {
62-
condition = var.vnet_name == null || var.resource_group != null
63-
error_message = "When vnet_name is set, resource_group must also be provided to look up the existing VNet and subnet."
68+
condition = var.vnet_name == null || var.resource_group != null || var.networking_resource_group != null
69+
error_message = "When vnet_name is set, resource_group or networking_resource_group must also be provided to look up the existing VNet and subnet."
6470
}
6571
}
6672

@@ -71,7 +77,7 @@ variable "vnet_cidr" {
7177
}
7278

7379
variable "subnet_name" {
74-
description = "Name of existing subnet. If null in bootstrap mode, a new subnet is created. Requires vnet_name and resource_group to be set."
80+
description = "Name of existing subnet. If null in bootstrap mode, a new subnet is created. Requires vnet_name and resource_group or networking_resource_group to be set."
7581
type = string
7682
default = null
7783
}

0 commit comments

Comments
 (0)