Skip to content

Conversation

@nightspotlight
Copy link
Contributor

@nightspotlight nightspotlight commented Jul 16, 2025

Description

Motivation and Context

This change will allow to simplify multi-region deployments of VPC resources. No longer need to maintain different provider aliases, one can simply pass region = "value" when calling the module. Example:

locals {
  regions = toset(["us-east-1", "us-west-2", "eu-west-1"])
}

module "vpc" {
  for_each = local.regions

  source = "terraform-aws-modules/vpc/aws"

  region = each.value

  name = "vpc-${each.value}"
}

Closes #1209.
Closes #1236.

Breaking Changes

None

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@nightspotlight
Copy link
Contributor Author

@antonbabenko , @bryantbiggs , ☝️😊

service = try(each.value.service, null)
service_name = try(each.value.service_name, null)
service_regions = try(coalescelist(compact([each.value.service_region])), null)
service_regions = try(coalescelist(compact([each.value.service_region])), [var.region], null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work…

│ Error: reading EC2 VPC Endpoint Services: couldn't find resource
│ 
│   with module.endpoints["emea"].data.aws_vpc_endpoint_service.this["secretsmanager"],
│   on .terraform/modules/endpoints/modules/vpc-endpoints/main.tf line 11, in data "aws_vpc_endpoint_service" "this":
│   11: data "aws_vpc_endpoint_service" "this" {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vpc_endpoint_service data source doesn't support the region parameter in v6.4.0. So it seems like it's going to the provider-set region, and so it's unable to find the service endpoint from a different region.

I just found the list of non-region-aware resources, and the aws_vpc_endpoint_service data source is one of them… 😟 https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/enhanced-region-support#non%E2%80%93region-aware-resources

Copy link
Contributor Author

@nightspotlight nightspotlight Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was able to get it to work but had to alter the endpoints map a little and had to add a new input variable in the module.

Before:

  endpoints = {
    s3 = {
      service = "s3"
      #
    }
  }

After:

  enable_service_endpoint_lookup = false
  endpoints = {
    s3 = {
      service_endpoint = "com.amazonaws.${each.value.aws_region}.s3"
      service_region   = each.value.aws_region
      #
    }
  }

The enable_service_endpoint_lookup switch effectively disables the aws_vpc_endpoint_service data source (default is enabled).

I need to work out and add some example scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated examples and readmes

@bryantbiggs bryantbiggs marked this pull request as draft July 21, 2025 19:35
@matheuscscp
Copy link

Looking forward to seeing this through 🙏

@antonszbx
Copy link

antonszbx commented Aug 20, 2025

@nightspotlight looking forward to it ❤️, afaik only example scripts are missing for usage? (for new endpoints)

@nightspotlight nightspotlight marked this pull request as ready for review August 20, 2025 12:22
@nightspotlight
Copy link
Contributor Author

@nightspotlight looking forward to it ❤️, afaik only example scripts are missing for usage? (for new endpoints)

hey, I've been using my fork in my project but without the endpoints part.

I updated examples and readme, I hope it gets reviewed soon.

@antonszbx
Copy link

@bryantbiggs @antonbabenko ✌️

@@ -0,0 +1,54 @@
provider "aws" {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need an example for this


data "aws_vpc_endpoint_service" "this" {
for_each = local.endpoints
for_each = { for k, v in local.endpoints : k => v if var.enable_service_endpoint_lookup }
Copy link
Member

@bryantbiggs bryantbiggs Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this change, use service_regions = var.region != null ? [var.region] : null instead


vpc_id = var.vpc_id
service_name = try(each.value.service_endpoint, data.aws_vpc_endpoint_service.this[each.key].service_name)
service_name = try(data.aws_vpc_endpoint_service.this[each.key].service_name, each.value.service_endpoint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these changes

default = {}
}

variable "enable_service_endpoint_lookup" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

}
```

### Region Support Limitation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@bryantbiggs bryantbiggs force-pushed the enhanced-region-support branch from 72d072c to 0fbc753 Compare September 22, 2025 15:26
@bryantbiggs bryantbiggs force-pushed the enhanced-region-support branch from 0fbc753 to b088ef2 Compare September 22, 2025 15:27
@bryantbiggs bryantbiggs changed the title feat: Enhanced region support feat: Add enhanced region support Sep 22, 2025
@bryantbiggs bryantbiggs merged commit fd357b9 into terraform-aws-modules:master Sep 22, 2025
20 checks passed
antonbabenko pushed a commit that referenced this pull request Sep 22, 2025
## [6.1.0](v6.0.1...v6.1.0) (2025-09-22)

### Features

* Add enhanced region support ([#1225](#1225)) ([fd357b9](fd357b9))
@antonbabenko
Copy link
Member

This PR is included in version 6.1.0 🎉

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

5 participants