-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
31 lines (26 loc) · 1.05 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
locals {
# Split the VPC cidr range in two.
# We'll use the first to sub-divide into private subnets and the second into public
private_subnet_cidr = cidrsubnet(var.vpc_cidr, 1, 0)
public_subnet_cidr = cidrsubnet(var.vpc_cidr, 1, 1)
create_ngws = var.create_private && var.create_public
use_all_azs = length(var.availability_zones) == 0
availability_zones = local.use_all_azs ? data.aws_availability_zones.available[0].zone_ids : var.availability_zones
private_subnet_count = length(module.subnets_private.subnet_ids)
public_subnet_count = length(module.subnets_public.subnet_ids)
# This will be length(azs) if both public and private enabled, and 0 otherwise
# We want to create NAT gateways only if we have both public and private subnets
ngw_count = min(local.public_subnet_count, local.private_subnet_count)
}
data "aws_availability_zones" "available" {
count = local.use_all_azs ? 1 : 0
state = "available"
}