From 934e8741e566f4bad3989c634232db548d42f6c0 Mon Sep 17 00:00:00 2001 From: Alex Somesan Date: Fri, 24 Mar 2017 10:41:45 +0100 Subject: [PATCH] Fixes for BYO VPC: * don't condition the creation of the VPC resource (https://github.com/hashicorp/hil/issues/50) * pass external subnet IDs into the VPC module --- modules/aws/vpc/variables.tf | 4 ++-- modules/aws/vpc/vpc-public.tf | 1 + modules/aws/vpc/vpc.tf | 15 +++++++++++---- platforms/aws/main.tf | 8 ++++---- platforms/aws/variables.tf | 12 +++++++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/modules/aws/vpc/variables.tf b/modules/aws/vpc/variables.tf index 78850e8d9e..a859a256d7 100644 --- a/modules/aws/vpc/variables.tf +++ b/modules/aws/vpc/variables.tf @@ -15,9 +15,9 @@ variable "external_vpc_id" { } variable "external_master_subnets" { - type = "list" + type = "list" } variable "external_worker_subnets" { - type = "list" + type = "list" } diff --git a/modules/aws/vpc/vpc-public.tf b/modules/aws/vpc/vpc-public.tf index ea0c3c07d3..629802e066 100644 --- a/modules/aws/vpc/vpc-public.tf +++ b/modules/aws/vpc/vpc-public.tf @@ -14,6 +14,7 @@ resource "aws_route_table" "default" { } resource "aws_main_route_table_association" "main_vpc_routes" { + count = "${var.external_vpc_id == "" ? 1 : 0}" vpc_id = "${data.aws_vpc.cluster_vpc.id}" route_table_id = "${aws_route_table.default.id}" } diff --git a/modules/aws/vpc/vpc.tf b/modules/aws/vpc/vpc.tf index b6bb9217c0..084e9f656b 100644 --- a/modules/aws/vpc/vpc.tf +++ b/modules/aws/vpc/vpc.tf @@ -1,14 +1,21 @@ data "aws_availability_zones" "azs" {} resource "aws_vpc" "new_vpc" { - count = "${length(var.external_vpc_id) > 0 ? 0 : 1}" - cidr_block = "${var.cidr_block}" + # count = "${length(var.external_vpc_id) > 0 ? 0 : 1}" + # + # We can't yet use the count gate here because of terraform issues: + # https://github.com/hashicorp/hil/issues/50 + # https://github.com/hashicorp/terraform/issues/11566 + # This should be re-enabled when above issues are fixed. + # + cidr_block = "${var.cidr_block}" + enable_dns_hostnames = true enable_dns_support = true tags { - Name = "${var.cluster_name}" - KubernetesCluster = "${var.cluster_name}" + Name = "${var.external_vpc_id == "" ? var.cluster_name : "${var.cluster_name}-side-effect"}" + KubernetesCluster = "${var.external_vpc_id == "" ? var.cluster_name : "${var.cluster_name}-side-effect"}" } } diff --git a/platforms/aws/main.tf b/platforms/aws/main.tf index de1f483e99..b5546cb1a3 100644 --- a/platforms/aws/main.tf +++ b/platforms/aws/main.tf @@ -1,15 +1,15 @@ data "aws_availability_zones" "azs" {} module "vpc" { - source = "../../modules/aws/vpc" + source = "../../modules/aws/vpc" az_count = "${var.tectonic_aws_az_count}" cidr_block = "${var.tectonic_aws_vpc_cidr_block}" cluster_name = "${var.tectonic_cluster_name}" external_vpc_id = "${var.tectonic_aws_external_vpc_id}" - external_master_subnets = [] - external_worker_subnets = [] + external_master_subnets = ["${compact(var.tectonic_aws_external_master_subnets)}"] + external_worker_subnets = ["${compact(var.tectonic_aws_external_worker_subnets)}"] } module "etcd" { @@ -89,4 +89,4 @@ module "workers" { ssh_key = "${var.tectonic_aws_ssh_key}" cl_channel = "${var.tectonic_cl_channel}" user_data = "${module.ignition-workers.ignition}" -} \ No newline at end of file +} diff --git a/platforms/aws/variables.tf b/platforms/aws/variables.tf index f3f0123df3..31ebe64601 100644 --- a/platforms/aws/variables.tf +++ b/platforms/aws/variables.tf @@ -24,4 +24,14 @@ variable "tectonic_aws_az_count" { variable "tectonic_aws_external_vpc_id" { type = "string" -} \ No newline at end of file +} + +variable "tectonic_aws_external_master_subnets" { + type = "list" + default = [""] +} + +variable "tectonic_aws_external_worker_subnets" { + type = "list" + default = [""] +}