Last active
March 27, 2023 02:31
-
-
Save AndrzejKomarnicki/8a4a0af9cab841b980f33024adcc63a4 to your computer and use it in GitHub Desktop.
AWS Local Zones AZ and subnet with Terraform VPC module
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
module "vpc" { | |
source = "terraform-aws-modules/vpc/aws" | |
version = "3.14.4" | |
name = var.name | |
cidr = "10.0.0.0/16" | |
azs = data.aws_availability_zones.available.names | |
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] | |
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"] | |
enable_nat_gateway = true | |
single_nat_gateway = true | |
enable_dns_hostnames = true | |
} | |
# Frankfurt AWS region AZ zone IDs are excluded in order to filter Warsaw AWS Local Zone | |
data "aws_availability_zones" "localzone" { | |
all_availability_zones = true | |
exclude_zone_ids = ["euc1-az2", "euc1-az3", "euc1-az1"] | |
filter { | |
name = "opt-in-status" | |
values = ["opted-in"] | |
} | |
} | |
resource "aws_subnet" "localzone" { | |
vpc_id = module.vpc.vpc_id | |
cidr_block = "10.0.10.0/24" | |
availability_zone = element(data.aws_availability_zones.localzone.names, 0) | |
tags = { | |
Name = "${local.localzone_az} subnet" | |
} | |
} | |
locals { | |
private_subnets = module.vpc.private_subnets | |
public_subnets = module.vpc.public_subnets | |
vpc_id = module.vpc.vpc_id | |
vpc_default_security_group_id = module.vpc.default_security_group_id | |
vpc_arn = module.vpc.vpc_arn | |
localzone_az = element(data.aws_availability_zones.localzone.names, 0) | |
localzone_subnet = aws_subnet.localzone.id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment