Skip to content

Commit

Permalink
update locals.tf to modify az behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jarpat committed Oct 5, 2023
1 parent 18e0340 commit 4ab6624
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/CONFIG-VARS.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ You can use `default_public_access_cidrs` to set a default range for all created
| :--- | ---: | ---: | ---: | ---: |
| vpc_cidr | Address space for the VPC | string | "192.168.0.0/16" | This variable is ignored when `vpc_id` is set (AKA bring your own VPC). |
| subnets | Subnets to be created and their settings | map | See below for default values | This variable is ignored when `subnet_ids` is set (AKA bring your own subnets). All defined subnets must exist within the VPC address space. |
| subnet_azs | Configure specific AZs you want the subnets to created in. The values must be distinct | optional map | {} see below for an example | If not defined or if not enough zones are listed to match the definitions in `subnets`, the code will perform a lookup to get a list of AZs in your selected region. This variable is ignored when `subnet_ids` is set (AKA bring your own subnets).|
| subnet_azs | Configure specific AZs you want the subnets to created in. The values must be distinct | optional map | {} see below for an example | If not defined or if any keys are not defined, the code will perform a lookup to get a list of AZs in your selected region. This variable is ignored when `subnet_ids` is set (AKA bring your own subnets).|

The default values for the subnets variable are as follows:

Expand Down
28 changes: 3 additions & 25 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,9 @@ locals {

# Generate list of AZ where created subnets should be placed
# If not specified by the user replace with list of all AZs in a region
# If not enough regions provided, append with the list of all AZs in the region while retaining
# order of user provided list of regions
public_subnet_azs = (
can(var.subnet_azs["public"]) ?
(length(var.subnet_azs["public"]) >= length(lookup(var.subnets, "public", [])) ?
var.subnet_azs["public"]
: distinct(concat(var.subnet_azs["public"], data.aws_availability_zones.available.names)))
: data.aws_availability_zones.available.names
)

private_subnet_azs = (
can(var.subnet_azs["private"]) ?
(length(var.subnet_azs["private"]) >= length(lookup(var.subnets, "private", [])) ?
var.subnet_azs["private"]
: distinct(concat(var.subnet_azs["private"], data.aws_availability_zones.available.names)))
: data.aws_availability_zones.available.names
)

database_subnet_azs = (
can(var.subnet_azs["database"]) ?
(length(var.subnet_azs["database"]) >= length(lookup(var.subnets, "database", [])) ?
var.subnet_azs["database"]
: distinct(concat(var.subnet_azs["database"], data.aws_availability_zones.available.names)))
: data.aws_availability_zones.available.names
)
public_subnet_azs = can(var.subnet_azs["public"]) ? var.subnet_azs["public"] : data.aws_availability_zones.available.names
private_subnet_azs = can(var.subnet_azs["private"]) ? var.subnet_azs["private"] : data.aws_availability_zones.available.names
database_subnet_azs = can(var.subnet_azs["database"]) ? var.subnet_azs["database"] : data.aws_availability_zones.available.names

ssh_public_key = (var.create_jump_vm || var.storage_type == "standard"
? file(var.ssh_public_key)
Expand Down

0 comments on commit 4ab6624

Please sign in to comment.