Skip to content

Commit

Permalink
modules/azure: Enable the use of external master & worker subnets
Browse files Browse the repository at this point in the history
- Only create master & worker subnets if no external vnets exist
- The `join()` interpolation function is used to work around
hashicorp/hil#50 when the subnets are conditionally
created. For more detail, see:
coreos@7ab31b0)
  • Loading branch information
metral committed May 5, 2017
1 parent fb4d397 commit 057e990
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Documentation/variables/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ This document gives an overview of the variables used in the different platforms
| tectonic_azure_create_dns_zone | If set to true, create an Azure DNS zone | string | `true` |
| tectonic_azure_dns_resource_group | | string | `tectonic-dns-group` |
| tectonic_azure_etcd_vm_size | Instance size for the etcd node(s). Example: Standard_DS2_v2. | string | `Standard_DS2_v2` |
| tectonic_azure_external_master_subnet_id | Subnet id within an existing VNet to deploy master nodes into. Required to use an existing VNet. Example: the subnet ID starts with `"/subscriptions/{subscriptionId}"` or `"/providers/{resourceProviderNamespace}"'`. | string | `` |
| tectonic_azure_external_rsg_name | Pre-existing resource group to use as parent for cluster resources. | string | `` |
| tectonic_azure_external_vnet_id | ID of an existing Virtual Network to launch nodes into. Example: VNet1. Leave blank to create a new Virtual Network. | string | `` |
| tectonic_azure_external_vnet_name | Pre-existing virtual network to create cluster into. | string | `` |
| tectonic_azure_external_worker_subnet_id | Subnet id within an existing VNet to deploy worker nodes into. Required to use an existing VNet. Example: the subnet ID starts with `"/subscriptions/{subscriptionId}"` or `"/providers/{resourceProviderNamespace}"'`. | string | `` |
| tectonic_azure_image_reference | The image ID as given in `azure image list`. Specifies the OS image of the VM. | map | `<map>` |
| tectonic_azure_location | | string | - |
| tectonic_azure_master_vm_size | Instance size for the master node(s). Example: Standard_DS2_v2. | string | `Standard_DS2_v2` |
Expand Down
6 changes: 6 additions & 0 deletions examples/terraform.tfvars.azure
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ tectonic_azure_dns_resource_group = "tectonic-dns-group"
// Instance size for the etcd node(s). Example: Standard_DS2_v2.
tectonic_azure_etcd_vm_size = "Standard_DS2_v2"

// Subnet id within an existing VNet to deploy master nodes into. Required to use an existing VNet. Example: the subnet ID starts with `"/subscriptions/{subscriptionId}"` or `"/providers/{resourceProviderNamespace}"'`.
tectonic_azure_external_master_subnet_id = ""

// Pre-existing resource group to use as parent for cluster resources.
tectonic_azure_external_rsg_name = ""

Expand All @@ -23,6 +26,9 @@ tectonic_azure_external_vnet_id = ""
// Pre-existing virtual network to create cluster into.
tectonic_azure_external_vnet_name = ""

// Subnet id within an existing VNet to deploy worker nodes into. Required to use an existing VNet. Example: the subnet ID starts with `"/subscriptions/{subscriptionId}"` or `"/providers/{resourceProviderNamespace}"'`.
tectonic_azure_external_worker_subnet_id = ""

//
tectonic_azure_image_reference = ""

Expand Down
7 changes: 2 additions & 5 deletions modules/azure/vnet/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ output "vnet_id" {
value = "${var.external_vnet_name == "" ? join("",azurerm_virtual_network.tectonic_vnet.*.name) : var.external_vnet_name }"
}

# We have to do this join() & split() 'trick' because null_data_source and
# the ternary operator can't output lists or maps
#
output "master_subnet" {
value = "${azurerm_subnet.master_subnet.id}"
value = "${var.external_vnet_name == "" ? join(" ", azurerm_subnet.master_subnet.*.id) : var.external_master_subnet_id }"
}

output "worker_subnet" {
value = "${azurerm_subnet.worker_subnet.id}"
value = "${var.external_vnet_name == "" ? join(" ", azurerm_subnet.worker_subnet.*.id) : var.external_worker_subnet_id }"
}
20 changes: 10 additions & 10 deletions modules/azure/vnet/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ variable "tectonic_cluster_name" {
type = "string"
}

variable "tectonic_azure_external_vnet_master_subnets" {
type = "list"
default = []
}

variable "tectonic_azure_external_vnet_worker_subnets" {
type = "list"
default = []
}

variable "resource_group_name" {
type = "string"
}
Expand All @@ -38,3 +28,13 @@ variable "external_vnet_name" {
type = "string"
default = ""
}

variable "external_master_subnet_id" {
type = "string"
default = ""
}

variable "external_worker_subnet_id" {
type = "string"
default = ""
}
2 changes: 2 additions & 0 deletions modules/azure/vnet/virtualnet.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ resource "azurerm_virtual_network" "tectonic_vnet" {
}

resource "azurerm_subnet" "master_subnet" {
count = "${var.external_vnet_name == "" ? 1 : 0}"
name = "${var.tectonic_cluster_name}_master_subnet"
resource_group_name = "${var.resource_group_name}"
virtual_network_name = "${var.external_vnet_name == "" ? join("",azurerm_virtual_network.tectonic_vnet.*.name) : var.external_vnet_name }"
address_prefix = "${cidrsubnet(var.vnet_cidr_block, 4, 0)}"
}

resource "azurerm_subnet" "worker_subnet" {
count = "${var.external_vnet_name == "" ? 1 : 0}"
name = "${var.tectonic_cluster_name}_worker_subnet"
resource_group_name = "${var.resource_group_name}"
virtual_network_name = "${var.external_vnet_name == "" ? join("",azurerm_virtual_network.tectonic_vnet.*.name) : var.external_vnet_name }"
Expand Down
2 changes: 2 additions & 0 deletions platforms/azure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module "vnet" {
tectonic_cluster_name = "${var.tectonic_cluster_name}"
vnet_cidr_block = "${var.tectonic_azure_vnet_cidr_block}"
external_vnet_name = "${var.tectonic_azure_external_vnet_name}"
external_master_subnet_id = "${var.tectonic_azure_external_master_subnet_id}"
external_worker_subnet_id = "${var.tectonic_azure_external_worker_subnet_id}"
}

module "etcd" {
Expand Down
12 changes: 12 additions & 0 deletions platforms/azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ variable "tectonic_azure_create_dns_zone" {
description = "If set to true, create an Azure DNS zone"
default = "true"
}

variable "tectonic_azure_external_master_subnet_id" {
type = "string"
description = "Subnet id within an existing VNet to deploy master nodes into. Required to use an existing VNet. Example: the subnet ID starts with `\"/subscriptions/{subscriptionId}\"` or `\"/providers/{resourceProviderNamespace}\"'`. "
default = ""
}

variable "tectonic_azure_external_worker_subnet_id" {
type = "string"
description = "Subnet id within an existing VNet to deploy worker nodes into. Required to use an existing VNet. Example: the subnet ID starts with `\"/subscriptions/{subscriptionId}\"` or `\"/providers/{resourceProviderNamespace}\"'`. "
default = ""
}

0 comments on commit 057e990

Please sign in to comment.