Skip to content

Instantly share code, notes, and snippets.

@blogumi
Last active April 4, 2020 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blogumi/bdacd6c8afc15db51b1f3fe24d5bef47 to your computer and use it in GitHub Desktop.
Save blogumi/bdacd6c8afc15db51b1f3fe24d5bef47 to your computer and use it in GitHub Desktop.
The below will create a 10.0.0.0/16 VPC, two 10.0.X.0/24 subnets, an internet gateway, and setup the subnet routing to route external traffic through the internet gateway:
# This data source is included for ease of sample architecture deployment
# and can be swapped out as necessary.
data "aws_availability_zones" "available" {
}
resource "aws_vpc" "demo" {
cidr_block = "10.0.0.0/16"
tags = {
"Name" = "terraform-eks-demo-node"
"kubernetes.io/cluster/${var.cluster-name}" = "shared"
}
}
resource "aws_subnet" "demo" {
count = 2
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = "10.0.${count.index}.0/24"
vpc_id = aws_vpc.demo.id
tags = {
"Name" = "terraform-eks-demo-node"
"kubernetes.io/cluster/${var.cluster-name}" = "shared"
}
}
resource "aws_internet_gateway" "demo" {
vpc_id = aws_vpc.demo.id
tags = {
Name = "terraform-eks-demo"
}
}
resource "aws_route_table" "demo" {
vpc_id = aws_vpc.demo.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.demo.id
}
}
resource "aws_route_table_association" "demo" {
count = 2
subnet_id = aws_subnet.demo[count.index].id
route_table_id = aws_route_table.demo.id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment