Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Commit

Permalink
modules/azure: Enable the use of external master & worker subnets (#550)
Browse files Browse the repository at this point in the history
* platforms/azure: add missing master_count to the tectonic module

* modules/azure: Enable the use of external master & worker subnets

- 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:
7ab31b0)
  • Loading branch information
metral authored and Sergiusz Urbaniak committed May 9, 2017
1 parent 4b732ff commit e0c2d67
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Documentation/variables/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ This document gives an overview of variables used in the Azure platform of the T
| tectonic_azure_config_version | (internal) This declares the version of the Azure configuration variables. It has no impact on generated assets but declares the version contract of the configuration. | string | `1.0` |
| 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 | (optional) Subnet ID within an existing VNet to deploy master nodes into. Required to use an existing VNet.<br><br>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 | (optional) Subnet ID within an existing VNet to deploy worker nodes into. Required to use an existing VNet.<br><br>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
12 changes: 12 additions & 0 deletions examples/terraform.tfvars.azure
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ 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"

// (optional) 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 @@ -25,6 +31,12 @@ tectonic_azure_external_vnet_id = ""
// Pre-existing virtual network to create cluster into.
tectonic_azure_external_vnet_name = ""

// (optional) 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
12 changes: 7 additions & 5 deletions platforms/azure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ module "resource_group" {
module "vnet" {
source = "../../modules/azure/vnet"

location = "${var.tectonic_azure_location}"
resource_group_name = "${module.resource_group.name}"
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}"
location = "${var.tectonic_azure_location}"
resource_group_name = "${module.resource_group.name}"
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
1 change: 1 addition & 0 deletions platforms/azure/tectonic.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module "tectonic" {
kubectl_client_id = "tectonic-kubectl"
ingress_kind = "NodePort"
experimental = "${var.tectonic_experimental}"
master_count = "${var.tectonic_master_count}"
}

resource "null_resource" "tectonic" {
Expand Down
26 changes: 26 additions & 0 deletions platforms/azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,29 @@ variable "tectonic_azure_use_custom_fqdn" {
description = "If set to true, assemble the FQDN from the configuration. Otherwise, use the FQDN set up by Azure."
default = "true"
}

variable "tectonic_azure_external_master_subnet_id" {
type = "string"

description = <<EOF
(optional) 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}"`.
EOF

default = ""
}

variable "tectonic_azure_external_worker_subnet_id" {
type = "string"

description = <<EOF
(optional) 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}"`.
EOF

default = ""
}

0 comments on commit e0c2d67

Please sign in to comment.