I would like to create a VPC in AWS with a private subnet and a public subnet. I am using Terraform.
Here is what I have so far:
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16" # <---
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "Main"
}
}
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.0.0/20" # <---
tags = {
Name = "Public"
}
}
resource "aws_subnet" "private" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.16.0/20" # <---
tags = {
Name = "Private"
}
}
The problem I am having is that I don't know how to choose appropriate CIDR blocks (3 to decide).
How do I determine what CIDR blocks to use?
A working combo might be:
10.16.0.0/16
10.16.0.0/24
10.16.128.0/24
Firstly there is nothing wrong with what you have done, each of the /20 subnets has half of the available IPs in the /16 VPC (4096 each less the 5 AWS reserved IPs).
In terms of how you decide, well this is a classic network design question that has been around for decades. An Internet search for "IP address range design best practice" will trawl-up several articles that might help.
Specifically for the AWS cloud then a few pointers: