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

Commit

Permalink
add variable vnet_location to customize vnet location (#45)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update

* update

* update

* update

* update

* update
  • Loading branch information
yupwei68 authored May 24, 2021
1 parent dce231d commit e3d043c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
location = "westus"
location = "westus"
vnet_location = "eastus"
1 change: 1 addition & 0 deletions test/fixture/variables.tf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
variable "location" {}
variable "vnet_location" {}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit e3d043c

Please sign in to comment.