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

Commit e3d043c

Browse files
authored
add variable vnet_location to customize vnet location (#45)
* update * update * update * update * update * update * update * update * update * update
1 parent dce231d commit e3d043c

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ resource "azurerm_resource_group" "example" {
5656
module "vnet" {
5757
source = "Azure/vnet/azurerm"
5858
resource_group_name = azurerm_resource_group.example.name
59+
vnet_location = "East US"
5960
address_space = ["10.0.0.0/16"]
6061
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
6162
subnet_names = ["subnet1", "subnet2", "subnet3"]

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ data azurerm_resource_group "vnet" {
66
resource azurerm_virtual_network "vnet" {
77
name = var.vnet_name
88
resource_group_name = data.azurerm_resource_group.vnet.name
9-
location = data.azurerm_resource_group.vnet.location
9+
location = var.vnet_location != null ? var.vnet_location : data.azurerm_resource_group.vnet.location
1010
address_space = var.address_space
1111
dns_servers = var.dns_servers
1212
tags = var.tags

test/fixture/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ resource "azurerm_resource_group" "test" {
1414
resource "azurerm_network_security_group" "nsg1" {
1515
name = "test-${random_id.rg_name.hex}-nsg"
1616
resource_group_name = azurerm_resource_group.test.name
17-
location = azurerm_resource_group.test.location
17+
location = var.vnet_location
1818
}
1919

2020
resource "azurerm_route_table" "rt1" {
21-
location = azurerm_resource_group.test.location
2221
name = "test-${random_id.rg_name.hex}-rt"
2322
resource_group_name = azurerm_resource_group.test.name
23+
location = var.vnet_location
2424
}
2525

2626
module "vnet" {
@@ -29,6 +29,7 @@ module "vnet" {
2929
address_space = ["10.0.0.0/16"]
3030
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
3131
subnet_names = ["subnet1", "subnet2", "subnet3"]
32+
vnet_location = var.vnet_location
3233

3334
nsg_ids = {
3435
subnet1 = azurerm_network_security_group.nsg1.id

test/fixture/terraform.tfvars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
location = "westus"
1+
location = "westus"
2+
vnet_location = "eastus"

test/fixture/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
variable "location" {}
2+
variable "vnet_location" {}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,9 @@ variable "tags" {
7474
ENV = "test"
7575
}
7676
}
77+
78+
variable "vnet_location" {
79+
description = "The location of the vnet to create. Defaults to the location of the resource group."
80+
type = string
81+
default = null
82+
}

0 commit comments

Comments
 (0)