From f3e46c7fbcce9f29d46d4346eaa570dc795e00bf Mon Sep 17 00:00:00 2001 From: sassdavid Date: Wed, 29 Jan 2025 08:34:51 +0100 Subject: [PATCH] feat: Support subnet_configuration in aws_vpc_endpoint resource --- examples/complete/main.tf | 7 +++++++ modules/vpc-endpoints/README.md | 16 +++++++++++++--- modules/vpc-endpoints/main.tf | 10 ++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 579a47395..0ac5553e6 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -122,6 +122,13 @@ module "vpc_endpoints" { service = "ecs" private_dns_enabled = true subnet_ids = module.vpc.private_subnets + subnet_configurations = [ + for v in module.vpc.private_subnet_objects : + { + ipv4 = cidrhost(v.cidr_block, 10) + subnet_id = v.id + } + ] }, ecs_telemetry = { create = false diff --git a/modules/vpc-endpoints/README.md b/modules/vpc-endpoints/README.md index 56377c3a5..2c4674639 100644 --- a/modules/vpc-endpoints/README.md +++ b/modules/vpc-endpoints/README.md @@ -26,9 +26,19 @@ module "endpoints" { tags = { Name = "dynamodb-vpc-endpoint" } }, sns = { - service = "sns" - subnet_ids = ["subnet-12345678", "subnet-87654321"] - tags = { Name = "sns-vpc-endpoint" } + service = "sns" + subnet_ids = ["subnet-12345678", "subnet-87654321"] + subnet_configurations = [ + { + ipv4 = "10.8.34.10" + subnet_id = "subnet-12345678" + }, + { + ipv4 = "10.8.35.10" + subnet_id = "subnet-87654321" + } + ] + tags = { Name = "sns-vpc-endpoint" } }, sqs = { service = "sqs" diff --git a/modules/vpc-endpoints/main.tf b/modules/vpc-endpoints/main.tf index 12d4e71ce..5e2d105b0 100644 --- a/modules/vpc-endpoints/main.tf +++ b/modules/vpc-endpoints/main.tf @@ -46,6 +46,16 @@ resource "aws_vpc_endpoint" "this" { } } + dynamic "subnet_configuration" { + for_each = try(each.value.subnet_configurations, []) + + content { + ipv4 = try(subnet_configuration.value.ipv4, null) + ipv6 = try(subnet_configuration.value.ipv6, null) + subnet_id = try(subnet_configuration.value.subnet_id, null) + } + } + tags = merge( var.tags, { "Name" = replace(each.key, ".", "-") },