From e3d043c8789d79ebc836b7b3526b37de732ad0fb Mon Sep 17 00:00:00 2001 From: Yuping Wei <56525716+yupwei68@users.noreply.github.com> Date: Mon, 24 May 2021 13:21:20 +0800 Subject: [PATCH] add variable `vnet_location` to customize vnet location (#45) * update * update * update * update * update * update * update * update * update * update --- README.md | 1 + main.tf | 2 +- test/fixture/main.tf | 5 +++-- test/fixture/terraform.tfvars | 3 ++- test/fixture/variables.tf | 1 + variables.tf | 6 ++++++ 6 files changed, 14 insertions(+), 4 deletions(-) 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 +}