2019-05-28 05:42:48 +02:00
|
|
|
data "aws_availability_zones" "all" {
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
|
|
|
|
# Network VPC, gateway, and routes
|
|
|
|
|
|
|
|
resource "aws_vpc" "network" {
|
2019-05-28 05:42:48 +02:00
|
|
|
cidr_block = var.host_cidr
|
2017-09-18 06:40:33 +02:00
|
|
|
assign_generated_ipv6_cidr_block = true
|
|
|
|
enable_dns_support = true
|
|
|
|
enable_dns_hostnames = true
|
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
tags = {
|
|
|
|
"Name" = var.cluster_name
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_internet_gateway" "gateway" {
|
2019-05-28 05:42:48 +02:00
|
|
|
vpc_id = aws_vpc.network.id
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
tags = {
|
|
|
|
"Name" = var.cluster_name
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_route_table" "default" {
|
2019-05-28 05:42:48 +02:00
|
|
|
vpc_id = aws_vpc.network.id
|
2017-09-18 06:40:33 +02:00
|
|
|
|
|
|
|
route {
|
|
|
|
cidr_block = "0.0.0.0/0"
|
2019-05-28 05:42:48 +02:00
|
|
|
gateway_id = aws_internet_gateway.gateway.id
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
route {
|
|
|
|
ipv6_cidr_block = "::/0"
|
2019-05-28 05:42:48 +02:00
|
|
|
gateway_id = aws_internet_gateway.gateway.id
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
tags = {
|
|
|
|
"Name" = var.cluster_name
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Subnets (one per availability zone)
|
|
|
|
|
|
|
|
resource "aws_subnet" "public" {
|
2019-05-28 05:42:48 +02:00
|
|
|
count = length(data.aws_availability_zones.all.names)
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
vpc_id = aws_vpc.network.id
|
|
|
|
availability_zone = data.aws_availability_zones.all.names[count.index]
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
cidr_block = cidrsubnet(var.host_cidr, 4, count.index)
|
|
|
|
ipv6_cidr_block = cidrsubnet(aws_vpc.network.ipv6_cidr_block, 8, count.index)
|
2017-09-18 06:40:33 +02:00
|
|
|
map_public_ip_on_launch = true
|
|
|
|
assign_ipv6_address_on_creation = true
|
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
tags = {
|
|
|
|
"Name" = "${var.cluster_name}-public-${count.index}"
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_route_table_association" "public" {
|
2019-05-28 05:42:48 +02:00
|
|
|
count = length(data.aws_availability_zones.all.names)
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
route_table_id = aws_route_table.default.id
|
2019-12-28 21:07:10 +01:00
|
|
|
subnet_id = aws_subnet.public.*.id[count.index]
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
2019-05-28 05:42:48 +02:00
|
|
|
|