-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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