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

  1. Create subnet ranges inside the network range.
  2. Use separate subnets for different trust boundaries.
  3. Add routes intentionally.
  4. 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.