Skip to content

feat: Enhanced region support #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nightspotlight
Copy link

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.

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
Author

@antonbabenko , @bryantbiggs , ☝️😊

@@ -13,7 +13,7 @@ data "aws_vpc_endpoint_service" "this" {

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
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
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
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.

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

Looking forward to seeing this through 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for region override in the module
2 participants