Skip to content

Commit 6f55e67

Browse files
committed
terraform/aws: remove option to use an existing vpc in aws
For the limited scope of the installer, we do not want the user to have the ability to share the VPC between clusters. A shared VPC could potentially be deleted when destroying one of the clusters, leaving the rest of the clusters using the shared VPC in an unusable state. Fixes https://jira.coreos.com/browse/CORS-873
1 parent 5813f61 commit 6f55e67

File tree

10 files changed

+15
-64
lines changed

10 files changed

+15
-64
lines changed

data/data/aws/main.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ module "dns" {
7575
elb_alias_enabled = true
7676
master_count = "${var.master_count}"
7777
private_zone_id = "${local.private_zone_id}"
78-
external_vpc_id = "${module.vpc.vpc_id}"
7978
extra_tags = "${var.aws_extra_tags}"
8079
private_endpoints = "${local.private_endpoints}"
8180
public_endpoints = "${local.public_endpoints}"
@@ -84,12 +83,11 @@ module "dns" {
8483
module "vpc" {
8584
source = "./vpc"
8685

87-
base_domain = "${var.base_domain}"
88-
cidr_block = "${var.aws_vpc_cidr_block}"
89-
cluster_id = "${var.cluster_id}"
90-
cluster_name = "${var.cluster_name}"
91-
external_vpc_id = "${var.aws_external_vpc_id}"
92-
region = "${var.aws_region}"
86+
base_domain = "${var.base_domain}"
87+
cidr_block = "${var.aws_vpc_cidr_block}"
88+
cluster_id = "${var.cluster_id}"
89+
cluster_name = "${var.cluster_name}"
90+
region = "${var.aws_region}"
9391

9492
external_master_subnet_ids = "${compact(var.aws_external_master_subnet_ids)}"
9593
external_worker_subnet_ids = "${compact(var.aws_external_worker_subnet_ids)}"

data/data/aws/route53/variables.tf

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ EOF
6060
default = false
6161
}
6262

63-
variable "external_vpc_id" {
64-
type = "string"
65-
66-
description = <<EOF
67-
ID of an existing VPC to launch nodes into.
68-
If unset a new VPC is created.
69-
70-
Example: `vpc-123456`
71-
EOF
72-
}
73-
7463
variable "private_endpoints" {
7564
description = <<EOF
7665
If set to true, create private-facing ingress resources (ELB, A-records).

data/data/aws/variables-aws.tf

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ This should not overlap with any other networks, such as a private datacenter co
4141
EOF
4242
}
4343

44-
variable "aws_external_vpc_id" {
45-
type = "string"
46-
47-
description = <<EOF
48-
(optional) ID of an existing VPC to launch nodes into.
49-
If unset a new VPC is created.
50-
51-
Example: `vpc-123456`
52-
EOF
53-
54-
default = ""
55-
}
56-
5744
variable "aws_endpoints" {
5845
description = <<EOF
5946
(optional) If set to "all", the default, then both public and private ingress resources (ELB, A-records) will be created.

data/data/aws/vpc/common.tf

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,22 @@ data "aws_availability_zones" "azs" {}
77

88
// Only reference data sources which are gauranteed to exist at any time (above) in this locals{} block
99
locals {
10-
// Define canonical source of truth for this
11-
external_vpc_mode = "${var.external_vpc_id != ""}"
12-
1310
// List of possible AZs for each type of subnet
1411
new_worker_subnet_azs = ["${coalescelist(keys(var.new_worker_subnet_configs), data.aws_availability_zones.azs.names)}"]
1512
new_master_subnet_azs = ["${coalescelist(keys(var.new_master_subnet_configs), data.aws_availability_zones.azs.names)}"]
1613

17-
// How many AZs to create worker and master subnets in (always zero if external_vpc_mode)
18-
new_worker_az_count = "${local.external_vpc_mode ? 0 : length(local.new_worker_subnet_azs)}"
19-
new_master_az_count = "${local.external_vpc_mode ? 0 : length(local.new_master_subnet_azs)}"
14+
// How many AZs to create worker and master subnets in
15+
new_worker_az_count = "${length(local.new_worker_subnet_azs)}"
16+
new_master_az_count = "${length(local.new_master_subnet_azs)}"
2017

2118
// The base set of ids needs to build rest of vpc data sources
22-
// This is crux of dealing with existing vpc / new vpc incongruity
23-
vpc_id = "${local.external_vpc_mode ? var.external_vpc_id : element(concat(aws_vpc.new_vpc.*.id,list("")),0)}"
19+
vpc_id = "${aws_vpc.new_vpc.id}"
2420

2521
// When referencing the _ids arrays or data source arrays via count = , always use the *_count variable rather than taking the length of the list
2622
worker_subnet_ids = ["${coalescelist(aws_subnet.worker_subnet.*.id,var.external_worker_subnet_ids)}"]
2723
master_subnet_ids = ["${coalescelist(aws_subnet.master_subnet.*.id,var.external_master_subnet_ids)}"]
28-
worker_subnet_count = "${local.external_vpc_mode ? length(var.external_worker_subnet_ids) : local.new_worker_az_count}"
29-
master_subnet_count = "${local.external_vpc_mode ? length(var.external_master_subnet_ids) : local.new_master_az_count}"
24+
worker_subnet_count = "${local.new_worker_az_count}"
25+
master_subnet_count = "${local.new_master_az_count}"
3026
}
3127

3228
# all data sources should be input variable-agnostic and used as canonical source for querying "state of resources" and building outputs

data/data/aws/vpc/variables.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ variable "cluster_name" {
1414
type = "string"
1515
}
1616

17-
variable "external_vpc_id" {
18-
type = "string"
19-
}
20-
2117
variable "external_master_subnet_ids" {
2218
type = "list"
2319
}

data/data/aws/vpc/vpc-public.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
resource "aws_internet_gateway" "igw" {
2-
count = "${local.external_vpc_mode ? 0 : 1}"
32
vpc_id = "${data.aws_vpc.cluster_vpc.id}"
43

54
tags = "${merge(map(
@@ -11,7 +10,6 @@ resource "aws_internet_gateway" "igw" {
1110
}
1211

1312
resource "aws_route_table" "default" {
14-
count = "${var.external_vpc_id == "" ? 1 : 0}"
1513
vpc_id = "${data.aws_vpc.cluster_vpc.id}"
1614

1715
tags = "${merge(map(
@@ -23,13 +21,11 @@ resource "aws_route_table" "default" {
2321
}
2422

2523
resource "aws_main_route_table_association" "main_vpc_routes" {
26-
count = "${local.external_vpc_mode ? 0 : 1}"
2724
vpc_id = "${data.aws_vpc.cluster_vpc.id}"
2825
route_table_id = "${aws_route_table.default.id}"
2926
}
3027

3128
resource "aws_route" "igw_route" {
32-
count = "${local.external_vpc_mode ? 0 : 1}"
3329
destination_cidr_block = "0.0.0.0/0"
3430
route_table_id = "${aws_route_table.default.id}"
3531
gateway_id = "${aws_internet_gateway.igw.id}"

data/data/aws/vpc/vpc.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ locals {
44
}
55

66
resource "aws_vpc" "new_vpc" {
7-
count = "${var.external_vpc_id == "" ? 1 : 0}"
87
cidr_block = "${var.cidr_block}"
98
enable_dns_hostnames = true
109
enable_dns_support = true

pkg/tfvars/aws/aws.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ type AWS struct {
2121
InstallerRole string `json:"aws_installer_role,omitempty"`
2222
Master `json:",inline"`
2323
Region string `json:"aws_region,omitempty"`
24-
VPCCIDRBlock string `json:"aws_vpc_cidr_block,omitempty"`
24+
VPCCIDRBlock string `json:"aws_vpc_cidr_block"`
2525
Worker `json:",inline"`
2626
}
2727

2828
// External converts external related config.
2929
type External struct {
3030
MasterSubnetIDs []string `json:"aws_external_master_subnet_ids,omitempty"`
3131
PrivateZone string `json:"aws_external_private_zone,omitempty"`
32-
VPCID string `json:"aws_external_vpc_id,omitempty"`
3332
WorkerSubnetIDs []string `json:"aws_external_worker_subnet_ids,omitempty"`
3433
}
3534

pkg/tfvars/tfvars.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ func TFVars(cfg *types.InstallConfig, bootstrapIgn, masterIgn string) ([]byte, e
8282
}
8383

8484
config.AWS = aws.AWS{
85-
Endpoints: aws.EndpointsAll, // Default value for endpoints.
86-
Region: cfg.Platform.AWS.Region,
87-
ExtraTags: cfg.Platform.AWS.UserTags,
88-
External: aws.External{
89-
VPCID: cfg.Platform.AWS.VPCID,
90-
},
85+
Endpoints: aws.EndpointsAll, // Default value for endpoints.
86+
Region: cfg.Platform.AWS.Region,
87+
ExtraTags: cfg.Platform.AWS.UserTags,
9188
VPCCIDRBlock: cfg.Platform.AWS.VPCCIDRBlock,
9289
EC2AMIOverride: ami,
9390
}

pkg/types/aws/platform.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ type Platform struct {
1414
// platform configuration.
1515
DefaultMachinePlatform *MachinePool `json:"defaultMachinePlatform,omitempty"`
1616

17-
// VPCID specifies the vpc to associate with the cluster.
18-
// If empty, new vpc will be created.
19-
// +optional
20-
VPCID string `json:"vpcID"`
21-
2217
// VPCCIDRBlock
23-
// +optional
2418
VPCCIDRBlock string `json:"vpcCIDRBlock"`
2519
}

0 commit comments

Comments
 (0)