diff --git a/README.md b/README.md index 6d2db38..91da3f9 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ resource "azurerm_resource_group" "example" { module "vnet" { source = "Azure/vnet/azurerm" resource_group_name = azurerm_resource_group.example.name + vnet_location = "East US" address_space = ["10.0.0.0/16"] subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] subnet_names = ["subnet1", "subnet2", "subnet3"] diff --git a/main.tf b/main.tf index 76e3973..434def5 100644 --- a/main.tf +++ b/main.tf @@ -6,7 +6,7 @@ data azurerm_resource_group "vnet" { resource azurerm_virtual_network "vnet" { name = var.vnet_name resource_group_name = data.azurerm_resource_group.vnet.name - location = data.azurerm_resource_group.vnet.location + location = var.vnet_location != null ? var.vnet_location : data.azurerm_resource_group.vnet.location address_space = var.address_space dns_servers = var.dns_servers tags = var.tags diff --git a/test/fixture/main.tf b/test/fixture/main.tf index bf84e15..0daa0b2 100644 --- a/test/fixture/main.tf +++ b/test/fixture/main.tf @@ -14,13 +14,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "nsg1" { name = "test-${random_id.rg_name.hex}-nsg" resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location + location = var.vnet_location } resource "azurerm_route_table" "rt1" { - location = azurerm_resource_group.test.location name = "test-${random_id.rg_name.hex}-rt" resource_group_name = azurerm_resource_group.test.name + location = var.vnet_location } module "vnet" { @@ -29,6 +29,7 @@ module "vnet" { address_space = ["10.0.0.0/16"] subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] subnet_names = ["subnet1", "subnet2", "subnet3"] + vnet_location = var.vnet_location nsg_ids = { subnet1 = azurerm_network_security_group.nsg1.id diff --git a/test/fixture/terraform.tfvars b/test/fixture/terraform.tfvars index 157b71d..2ec245d 100644 --- a/test/fixture/terraform.tfvars +++ b/test/fixture/terraform.tfvars @@ -1 +1,2 @@ -location = "westus" +location = "westus" +vnet_location = "eastus" diff --git a/test/fixture/variables.tf b/test/fixture/variables.tf index f875d56..dc8c56f 100644 --- a/test/fixture/variables.tf +++ b/test/fixture/variables.tf @@ -1 +1,2 @@ variable "location" {} +variable "vnet_location" {} diff --git a/variables.tf b/variables.tf index 82d15f5..5f6a0ca 100644 --- a/variables.tf +++ b/variables.tf @@ -74,3 +74,9 @@ variable "tags" { ENV = "test" } } + +variable "vnet_location" { + description = "The location of the vnet to create. Defaults to the location of the resource group." + type = string + default = null +}