Skip to content

Commit

Permalink
Merge pull request #43 from dduportal/fix/vpc/use-array-for-subnets
Browse files Browse the repository at this point in the history
fix(vpc) order subnets with array to avoid unexpected destroy/recreate when only adding subnets
  • Loading branch information
dduportal authored Nov 27, 2024
2 parents d7b78fe + a54956e commit 79fd7ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
33 changes: 18 additions & 15 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,32 @@ locals {
## VPC Setup
vpc_cidr = "10.0.0.0/16" # cannot be less then /16 (more ips)
# Public subnets use the first partition of the vpc_cidr (index 0)
vpc_public_subnets = {
"controller" = {
az = format("${local.region}%s", "b"),
vpc_public_subnets = [
{
name = "controller",
az = format("${local.region}%s", "b"),
# First /23 of the first subset of the VPC (split in 2)
cidr = cidrsubnet(cidrsubnets(local.vpc_cidr, 1, 1)[0], 6, 0)
},
}
]
# Public subnets use the second partition of the vpc_cidr (index 1)
vpc_private_subnets = {
"vm-agents-1" = {
az = format("${local.region}%s", "b"),
vpc_private_subnets = [
{
name = "eks-1",
az = format("${local.region}%s", "b"),
# Second /23 of the second subset of the VPC (split in 2)
cidr = cidrsubnet(cidrsubnets(local.vpc_cidr, 1, 1)[1], 6, 1)
},
{
name = "vm-agents-1",
az = format("${local.region}%s", "b"),
# First /23 of the second subset of the VPC (split in 2)
cidr = cidrsubnet(cidrsubnets(local.vpc_cidr, 1, 1)[1], 6, 0)
},
"eks-1" = {
az = format("${local.region}%s", "b"),
# Second /23 of the second subset of the VPC (split in 2)
cidr = cidrsubnet(cidrsubnets(local.vpc_cidr, 1, 1)[1], 6, 1)
}
"eks-2" = {
az = format("${local.region}%s", "c"),
{ name = "eks-2",
az = format("${local.region}%s", "c"),
# Third /23 of the second subset of the VPC (split in 2)
cidr = cidrsubnet(cidrsubnets(local.vpc_cidr, 1, 1)[1], 6, 2)
}
}
]
}
4 changes: 2 additions & 2 deletions vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module "vpc" {
azs = [for subnet_name, subnet_data in local.vpc_private_subnets : subnet_data.az]

# only private subnets for security (to control allowed outbound connections)
private_subnets = [for subnet_name, subnet_data in local.vpc_private_subnets : subnet_data.cidr]
public_subnets = [for subnet_name, subnet_data in local.vpc_public_subnets : subnet_data.cidr]
private_subnets = [for subnet in local.vpc_private_subnets : subnet.cidr]
public_subnets = [for subnet in local.vpc_public_subnets : subnet.cidr]

public_subnet_ipv6_prefixes = range(length(local.vpc_public_subnets))
private_subnet_ipv6_prefixes = range(10, length(local.vpc_private_subnets) + 10)
Expand Down

0 comments on commit 79fd7ed

Please sign in to comment.