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

Fix infrastructure subnet #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ credentials.yml
*control-plane-*.yml
*.tgz
*secrets.yml
*override.tf
5 changes: 2 additions & 3 deletions modules/infra/nat.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
resource "aws_route_table" "deployment" {
count = "${length(var.availability_zones)}"
vpc_id = "${aws_vpc.vpc.id}"
}

Expand Down Expand Up @@ -44,9 +43,9 @@ resource "aws_eip" "nat_eip" {
}

resource "aws_route" "toggle_internet" {
count = "${var.internetless ? 0 : length(var.availability_zones)}"
count = "${var.internetless ? 0 : 1}"

route_table_id = "${element(aws_route_table.deployment.*.id, count.index)}"
route_table_id = "${aws_route_table.deployment.id}"
nat_gateway_id = "${aws_nat_gateway.nat.id}"
destination_cidr_block = "0.0.0.0/0"
}
20 changes: 8 additions & 12 deletions modules/infra/networking.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# Bosh Director Subnet
resource "aws_subnet" "infrastructure_subnets" {
count = "${length(var.availability_zones)}"
resource "aws_subnet" "infrastructure_subnet" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${cidrsubnet(local.infrastructure_cidr, 2, count.index)}"
availability_zone = "${element(var.availability_zones, count.index)}"
cidr_block = "${cidrsubnet(local.infrastructure_cidr, 2, 0)}"
availability_zone = "${element(var.availability_zones, 0)}"

tags = "${merge(var.tags, map("Name", "${var.env_name}-infrastructure-subnet${count.index}"))}"
tags = "${merge(var.tags, map("Name", "${var.env_name}-infrastructure-subnet"))}"
}

data "template_file" "infrastructure_subnet_gateways" {
# Render the template once for each availability zone
count = "${length(var.availability_zones)}"
data "template_file" "infrastructure_subnet_gateway" {
template = "$${gateway}"

vars {
gateway = "${cidrhost(element(aws_subnet.infrastructure_subnets.*.cidr_block, count.index), 1)}"
gateway = "${cidrhost(aws_subnet.infrastructure_subnet.cidr_block, 1)}"
}
}

resource "aws_route_table_association" "route_infrastructure_subnets" {
count = "${length(var.availability_zones)}"
subnet_id = "${element(aws_subnet.infrastructure_subnets.*.id, count.index)}"
route_table_id = "${element(aws_route_table.deployment.*.id, count.index)}"
subnet_id = "${aws_subnet.infrastructure_subnet.id}"
route_table_id = "${element(aws_route_table.deployment.id, count.index)}"
}

# Ops Manager Subnet
Expand Down
10 changes: 5 additions & 5 deletions modules/infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ output "public_subnet_cidrs" {
}

output "infrastructure_subnet_ids" {
value = ["${aws_subnet.infrastructure_subnets.*.id}"]
value = ["${aws_subnet.infrastructure_subnet.id}"]
}

output "infrastructure_subnets" {
value = ["${aws_subnet.infrastructure_subnets.*.id}"]
value = ["${aws_subnet.infrastructure_subnet.id}"]
}

output "infrastructure_subnet_availability_zones" {
value = ["${aws_subnet.infrastructure_subnets.*.availability_zone}"]
value = ["${aws_subnet.infrastructure_subnet.availability_zone}"]
}

output "infrastructure_subnet_cidrs" {
value = ["${aws_subnet.infrastructure_subnets.*.cidr_block}"]
value = ["${aws_subnet.infrastructure_subnet.cidr_block}"]
}

output "infrastructure_subnet_gateways" {
value = ["${data.template_file.infrastructure_subnet_gateways.*.rendered}"]
value = ["${data.template_file.infrastructure_subnet_gateway.rendered}"]
}

output "aws_lb_interface_endpoint_ips" {
Expand Down
4 changes: 2 additions & 2 deletions modules/infra/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ resource "aws_vpc_endpoint" "ec2" {
vpc_id = "${aws_vpc.vpc.id}"
service_name = "${local.ec2_address}"
vpc_endpoint_type = "Interface"
subnet_ids = ["${aws_subnet.infrastructure_subnets.*.id}"]
subnet_ids = ["${aws_subnet.infrastructure_subnet.id}"]
private_dns_enabled = true
security_group_ids = ["${aws_security_group.vms_security_group.id}"]
}
Expand All @@ -50,7 +50,7 @@ resource "aws_vpc_endpoint" "lb" {
vpc_id = "${aws_vpc.vpc.id}"
service_name = "${local.lb_api_address}"
vpc_endpoint_type = "Interface"
subnet_ids = ["${aws_subnet.infrastructure_subnets.*.id}"]
subnet_ids = ["${aws_subnet.infrastructure_subnet.id}"]
private_dns_enabled = true
security_group_ids = ["${aws_security_group.vms_security_group.id}"]
}
Expand Down
11 changes: 9 additions & 2 deletions terraforming-control-plane/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ output "public_subnet_cidrs" {
value = "${module.infra.public_subnet_cidrs}"
}

output "infrastructure_subnet_ids" {
value = "${module.infra.infrastructure_subnet_ids}"
output "infrastructure_subnet_id" {
value = "${element(module.infra.infrastructure_subnet_ids, 0)}"
}

output "infrastructure_subnets" {
Expand Down Expand Up @@ -201,3 +201,10 @@ output "control_plane_web_security_group" {
output "control_plane_lb_ca_cert" {
value = "${var.tls_ca_certificate}"
}

# Deprecated ===================================================================

output "infrastructure_subnet_ids" {
value = "${module.infra.infrastructure_subnet_ids}"
}

8 changes: 6 additions & 2 deletions terraforming-pas/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ output "public_subnet_cidrs" {
value = "${module.infra.public_subnet_cidrs}"
}

output "infrastructure_subnet_ids" {
value = "${module.infra.infrastructure_subnet_ids}"
output "infrastructure_subnet_id" {
value = "${element(module.infra.infrastructure_subnet_ids, 0)}"
}

output "infrastructure_subnets" {
Expand Down Expand Up @@ -304,3 +304,7 @@ output "management_subnet_cidrs" {
output "management_subnet_gateways" {
value = "${module.infra.infrastructure_subnet_gateways}"
}

output "infrastructure_subnet_ids" {
value = "${module.infra.infrastructure_subnet_ids}"
}
10 changes: 8 additions & 2 deletions terraforming-pks/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ output "public_subnet_cidrs" {
value = "${module.infra.public_subnet_cidrs}"
}

output "infrastructure_subnet_ids" {
value = "${module.infra.infrastructure_subnet_ids}"
output "infrastructure_subnet_id" {
value = "${element(module.infra.infrastructure_subnet_ids, 0)}"
}

output "infrastructure_subnets" {
Expand Down Expand Up @@ -226,3 +226,9 @@ output "services_subnet_gateways" {
output "tags" {
value = "${local.actual_tags}"
}

# Deprecated ===================================================================

output "infrastructure_subnet_ids" {
value = "${module.infra.infrastructure_subnet_ids}"
}