Skip to content

Instantly share code, notes, and snippets.

@egonSchiele
Created April 17, 2025 14:21
Show Gist options
  • Select an option

  • Save egonSchiele/baacf713942e9343942b1d8af6df8aa2 to your computer and use it in GitHub Desktop.

Select an option

Save egonSchiele/baacf713942e9343942b1d8af6df8aa2 to your computer and use it in GitHub Desktop.
Terraform code for everything up to and including the chapter on route tables on DuckTyped. See the full series here: https://www.ducktyped.org/p/a-mini-book-on-aws-networking-introduction
# Boilerplate code
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-west-1"
# This will tag all resources we create
# so we can easily find them later to delete.
default_tags {
tags = {
Terraform = "true"
}
}
}
# Make a VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform"
}
}
# Make a subnet
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
}
# Make an internet gateway
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
}
# Make a route table with one route,
# which matches any IP address and
# sends it to the internet gateway.
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
}
# Associate the route table with the subnet.
resource "aws_route_table_association" "public_subnet_asso" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment