Skip to content

Commit

Permalink
data/azure: re-organize vnet to create explicit deps to internal dns …
Browse files Browse the repository at this point in the history
…zone before any resource in vnet

Previous commit [1] created explicit deps to make sure VMs were not created before internal DNS zone and VNET attachement.
There is still cases where LBs etc like resources in VNET block the internal DNS zone creation because of azure issues [2]

[1]: 08c8bc5
[2]: MicrosoftDocs/azure-docs#13728
  • Loading branch information
abhinavdahiya committed May 29, 2019
1 parent cc44c74 commit 8ac9ab4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
13 changes: 12 additions & 1 deletion data/data/azure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" {
Expand Down Expand Up @@ -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]
}
2 changes: 0 additions & 2 deletions data/data/azure/vnet/common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions data/data/azure/vnet/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
output "vnet_id" {
value = local.vnet_id
}

output "cluster-pip" {
value = azurerm_public_ip.cluster_public_ip.ip_address
}
Expand Down
8 changes: 8 additions & 0 deletions data/data/azure/vnet/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
variable "vnet_name" {
type = string
}

variable "vnet_cidr" {
type = string
}
Expand Down Expand Up @@ -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"
}
11 changes: 2 additions & 9 deletions data/data/azure/vnet/vnet.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
}

0 comments on commit 8ac9ab4

Please sign in to comment.