diff --git a/data/data/azure/main.tf b/data/data/azure/main.tf index 508ab1d6212..5093a4dd907 100644 --- a/data/data/azure/main.tf +++ b/data/data/azure/main.tf @@ -39,6 +39,7 @@ module "bootstrap" { module "vnet" { source = "./vnet" + vnet_name = azurerm_virtual_network.cluster_vnet.name resource_group_name = azurerm_resource_group.main.name vnet_cidr = var.machine_cidr master_subnet_cidr = local.master_subnet_cidr @@ -47,6 +48,9 @@ module "vnet" { region = var.azure_region dns_label = var.cluster_id master_count = var.master_count + + # This is to create explicit dependency on private zone to exist before VMs are created in the vnet. https://github.com/MicrosoftDocs/azure-docs/issues/13728 + private_dns_zone_id = azurerm_dns_zone.private.id } module "master" { @@ -123,5 +127,12 @@ resource "azurerm_dns_zone" "private" { name = var.cluster_domain resource_group_name = azurerm_resource_group.main.name zone_type = "Private" - resolution_virtual_network_ids = [module.vnet.vnet_id] + resolution_virtual_network_ids = [azurerm_virtual_network.cluster_vnet.id] +} + +resource "azurerm_virtual_network" "cluster_vnet" { + name = "${var.cluster_id}-vnet" + resource_group_name = azurerm_resource_group.main.name + location = var.azure_region + address_space = [var.machine_cidr] } diff --git a/data/data/azure/vnet/common.tf b/data/data/azure/vnet/common.tf index 8304830352b..227f9f12fdf 100644 --- a/data/data/azure/vnet/common.tf +++ b/data/data/azure/vnet/common.tf @@ -3,8 +3,6 @@ // Only reference data sources which are guaranteed to exist at any time (above) in this locals{} block locals { - vnet_id = azurerm_virtual_network.cluster_vnet.id - subnet_ids = azurerm_subnet.master_subnet.id lb_fqdn = azurerm_lb.public.id diff --git a/data/data/azure/vnet/outputs.tf b/data/data/azure/vnet/outputs.tf index 9e3e2f5fbe2..71250b2b702 100644 --- a/data/data/azure/vnet/outputs.tf +++ b/data/data/azure/vnet/outputs.tf @@ -1,7 +1,3 @@ -output "vnet_id" { - value = local.vnet_id -} - output "cluster-pip" { value = azurerm_public_ip.cluster_public_ip.ip_address } diff --git a/data/data/azure/vnet/variables.tf b/data/data/azure/vnet/variables.tf index 3973ab835a4..d37b65fe3b6 100644 --- a/data/data/azure/vnet/variables.tf +++ b/data/data/azure/vnet/variables.tf @@ -1,3 +1,7 @@ +variable "vnet_name" { + type = string +} + variable "vnet_cidr" { type = string } @@ -53,3 +57,7 @@ variable "master_count" { default = "3" } +variable "private_dns_zone_id" { + type = string + description = "This is to create explicit dependency on private zone to exist before VMs are created in the vnet. https://github.com/MicrosoftDocs/azure-docs/issues/13728" +} diff --git a/data/data/azure/vnet/vnet.tf b/data/data/azure/vnet/vnet.tf index f8362ecd5ad..607cdec968b 100644 --- a/data/data/azure/vnet/vnet.tf +++ b/data/data/azure/vnet/vnet.tf @@ -1,10 +1,3 @@ -resource "azurerm_virtual_network" "cluster_vnet" { - name = "${var.cluster_id}-vnet" - resource_group_name = var.resource_group_name - location = var.region - address_space = [var.vnet_cidr] -} - resource "azurerm_route_table" "route_table" { name = "${var.cluster_id}-node-routetable" location = var.region @@ -14,14 +7,14 @@ resource "azurerm_route_table" "route_table" { resource "azurerm_subnet" "master_subnet" { resource_group_name = var.resource_group_name address_prefix = var.master_subnet_cidr - virtual_network_name = azurerm_virtual_network.cluster_vnet.name + virtual_network_name = var.vnet_name name = "${var.cluster_id}-controlplane-subnet" } resource "azurerm_subnet" "node_subnet" { resource_group_name = var.resource_group_name address_prefix = var.node_subnet_cidr - virtual_network_name = azurerm_virtual_network.cluster_vnet.name + virtual_network_name = var.vnet_name name = "${var.cluster_id}-node-subnet" }