Lesson 2 of 4 ยท Build a Cloud Foundation
Subnets and routing
Subnets divide a virtual network into smaller address ranges. Routing determines where traffic may go. A subnet is not public merely because its name says public; it needs an appropriate route and the workload must be configured deliberately.
Example
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
}
resource "aws_subnet" "private" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.2.0/24"
}Step by step
- Create subnet ranges inside the network range.
- Use separate subnets for different trust boundaries.
- Add routes intentionally.
- Check which resources need inbound internet access.
Common mistakes to avoid
- Putting every workload in one subnet.
- Assuming a private subnet can reach the internet without a planned egress path.