Skip to content

Commit eeb2249

Browse files
committed
fix: derive subnet CIDRs via cidrsubnet instead of hardcoding
1 parent b5330b4 commit eeb2249

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

terraform/vpc.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ locals {
1414

1515
azs = slice(data.aws_availability_zones.available.names, 0, local.az_count)
1616

17-
# Match the deployed subnet layout (explicit /24 blocks within the VPC CIDR).
18-
public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24"]
19-
private_subnet_cidrs = ["10.0.10.0/24", "10.0.20.0/24"]
17+
# Derive /24 subnet ranges from the VPC CIDR.
18+
# Network numbers are intentionally spaced so public (1,2) and private (10,20)
19+
# blocks don't collide and are easy to identify at a glance.
20+
public_subnet_cidrs = [for i in [1, 2] : cidrsubnet(var.vpc_cidr, 8, i)]
21+
private_subnet_cidrs = [for i in [10, 20] : cidrsubnet(var.vpc_cidr, 8, i)]
2022
}
2123

2224
resource "aws_vpc" "this" {

0 commit comments

Comments
 (0)