-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: always assume 3 network CIDRr for public and private
Without this we get into problems when we extend/change the network and CIDRs clash
- Loading branch information
1 parent
7688e71
commit 55349e1
Showing
7 changed files
with
99 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
module "network" { | ||
source = "../../" | ||
name = "name" | ||
region = "eu-west-1" | ||
# public_subnet_zones = ["a", "b", "c"] | ||
source = "../../" | ||
name = "name" | ||
region = "eu-west-1" | ||
private_subnet_zones = ["a", "b", "c"] | ||
public_subnet_cidrs = ["172.20.32.0/19", "172.20.64.0/19", "172.20.96.0/19"] | ||
private_subnet_cidrs = ["173.20.32.0/19", "173.20.64.0/19", "173.20.96.0/19"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module "network" { | ||
source = "../../" | ||
name = "name" | ||
region = "eu-west-1" | ||
public_subnet_cidrs = { a = "172.20.32.0/19", b = "172.20.64.0/19", c = "172.20.96.0/19" } | ||
private_subnet_cidrs = { a = "173.20.32.0/19", b = "173.20.64.0/19", c = "173.20.96.0/19" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
provider "aws" { | ||
skip_requesting_account_id = true | ||
skip_credentials_validation = true | ||
skip_metadata_api_check = true | ||
s3_force_path_style = true | ||
region = "eu-west-1" | ||
access_key = "mock_access_key" | ||
secret_key = "mock_secret_key" | ||
} | ||
|
||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module "network" { | ||
source = "../../" | ||
name = "name" | ||
region = "eu-west-1" | ||
public_subnet_zones = ["a", "b", "c"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
provider "aws" { | ||
skip_requesting_account_id = true | ||
skip_credentials_validation = true | ||
skip_metadata_api_check = true | ||
s3_force_path_style = true | ||
region = "eu-west-1" | ||
access_key = "mock_access_key" | ||
secret_key = "mock_secret_key" | ||
} | ||
|
||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
locals { | ||
cidrs = cidrsubnets(var.vpc_cidr, 3, 3, 3, 3, 3, 3) | ||
|
||
number_of_private_zones = length(var.private_subnet_zones) | ||
create_private_subnets = local.number_of_private_zones > 0 | ||
public_zones_to_cidr = zipmap(["a", "b", "c"], slice(local.cidrs, 0, 3)) | ||
private_zones_to_cidr = zipmap(["a", "b", "c"], slice(local.cidrs, 3, 6)) | ||
|
||
provided_cidrs_from_private_zones = length(var.public_subnet_cidrs) > 0 && length(var.private_subnet_zones) > 0 ? zipmap(var.private_subnet_zones, var.public_subnet_cidrs) : {} | ||
provided_cidrs_from_public_zones = length(var.public_subnet_cidrs) > 0 ? zipmap(var.public_subnet_zones, var.public_subnet_cidrs) : {} | ||
provided_cidrs = local.create_private_subnets ? local.provided_cidrs_from_private_zones : local.provided_cidrs_from_public_zones | ||
// if private zones > public zones | ||
// replace with private zones | ||
public_zones = length(var.public_subnet_zones) < length(var.private_subnet_zones) ? var.private_subnet_zones : var.public_subnet_zones | ||
private_zones = var.private_subnet_zones | ||
|
||
generated_cidrs_from_private_zones = zipmap(var.private_subnet_zones, slice(local.cidrs, 0, local.number_of_private_zones)) | ||
generated_cidrs_from_public_zones = zipmap(var.public_subnet_zones, slice(local.cidrs, 0, length(var.public_subnet_zones))) | ||
generated_cidrs = local.create_private_subnets ? local.generated_cidrs_from_private_zones : local.generated_cidrs_from_public_zones | ||
// if provided zones | ||
override = length(var.public_subnet_cidrs) > 0 | ||
|
||
public_cidrs = length(var.public_subnet_cidrs) > 0 ? local.provided_cidrs : local.generated_cidrs | ||
private_cidrs = length(var.private_subnet_cidrs) > 0 ? zipmap(var.private_subnet_zones, var.private_subnet_cidrs) : zipmap(var.private_subnet_zones, slice(local.cidrs, length(local.public_cidrs), length(local.public_cidrs) + local.number_of_private_zones)) | ||
create_private_subnets = length(var.private_subnet_zones) > 0 | ||
|
||
public_cidrs = local.override ? var.public_subnet_cidrs : tomap({ for z in local.public_zones : z => local.public_zones_to_cidr[z] }) | ||
private_cidrs = local.override ? var.private_subnet_cidrs : tomap({ for z in local.private_zones : z => local.private_zones_to_cidr[z] }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters