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
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
tags = {
|
|
|
|
"Name" = var.cluster_name
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
2020-02-26 08:12:19 +01:00
|
|
|
resource "aws_route" "egress-ipv4" {
|
2020-04-01 06:42:51 +02:00
|
|
|
route_table_id = aws_route_table.default.id
|
2020-02-26 08:12:19 +01:00
|
|
|
destination_cidr_block = "0.0.0.0/0"
|
2020-04-01 06:42:51 +02:00
|
|
|
gateway_id = aws_internet_gateway.gateway.id
|
2020-02-26 08:12:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_route" "egress-ipv6" {
|
2020-04-01 06:42:51 +02:00
|
|
|
route_table_id = aws_route_table.default.id
|
2020-02-26 08:12:19 +01:00
|
|
|
destination_ipv6_cidr_block = "::/0"
|
2020-04-01 06:42:51 +02:00
|
|
|
gateway_id = aws_internet_gateway.gateway.id
|
2020-02-26 08:12:19 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-08-23 05:02:53 +02:00
|
|
|
tags = {
|
|
|
|
"Name" = "${var.cluster_name}-public-${count.index}"
|
|
|
|
}
|
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
|
|
|
|
2024-08-23 05:02:53 +02:00
|
|
|
# IPv4 and IPv6 CIDR blocks
|
|
|
|
cidr_block = cidrsubnet(var.host_cidr, 4, count.index)
|
|
|
|
ipv6_cidr_block = cidrsubnet(aws_vpc.network.ipv6_cidr_block, 8, count.index)
|
|
|
|
|
|
|
|
# Assign IPv4 and IPv6 addresses to instances
|
2017-09-18 06:40:33 +02:00
|
|
|
map_public_ip_on_launch = true
|
|
|
|
assign_ipv6_address_on_creation = true
|
|
|
|
|
2024-08-23 05:02:53 +02:00
|
|
|
# Hostnames assigned to instances
|
|
|
|
# resource-name: <ec2-instance-id>.region.compute.internal
|
|
|
|
private_dns_hostname_type_on_launch = "resource-name"
|
|
|
|
enable_resource_name_dns_a_record_on_launch = true
|
|
|
|
enable_resource_name_dns_aaaa_record_on_launch = true
|
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
|
|
|
|