Skip to content

Commit a77de68

Browse files
Workaround for service endpoint lookup in the wrong region
1 parent dc91032 commit a77de68

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

modules/vpc-endpoints/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ No modules.
9494
|------|-------------|------|---------|:--------:|
9595
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created | `bool` | `true` | no |
9696
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | Determines if a security group is created | `bool` | `false` | no |
97+
| <a name="input_enable_service_endpoint_lookup"></a> [enable\_service\_endpoint\_lookup](#input\_enable\_service\_endpoint\_lookup) | Determines whether to look up the service endpoint in the AWS API. If set to false, the `service_endpoint` attribute (usually in the form of `com.amazonaws.<region>.<service>`) must be provided in the `endpoints` map | `bool` | `true` | no |
9798
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | A map of interface and/or gateway endpoints containing their properties and configurations | `any` | `{}` | no |
9899
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the region set in the provider configuration | `string` | `null` | no |
99100
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | Description of the security group created | `string` | `null` | no |

modules/vpc-endpoints/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ locals {
99
}
1010

1111
data "aws_vpc_endpoint_service" "this" {
12-
for_each = local.endpoints
12+
for_each = { for k, v in local.endpoints : k => v if var.enable_service_endpoint_lookup }
1313

1414
service = try(each.value.service, null)
1515
service_name = try(each.value.service_name, null)
16-
service_regions = try(coalescelist(compact([each.value.service_region])), [var.region], null)
16+
service_regions = try(coalescelist(compact([each.value.service_region])), null)
1717

1818
filter {
1919
name = "service-type"
@@ -27,7 +27,7 @@ resource "aws_vpc_endpoint" "this" {
2727
region = var.region
2828

2929
vpc_id = var.vpc_id
30-
service_name = try(each.value.service_endpoint, data.aws_vpc_endpoint_service.this[each.key].service_name)
30+
service_name = try(data.aws_vpc_endpoint_service.this[each.key].service_name, each.value.service_endpoint)
3131
service_region = try(each.value.service_region, null)
3232
vpc_endpoint_type = try(each.value.service_type, "Interface")
3333
auto_accept = try(each.value.auto_accept, null)

modules/vpc-endpoints/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ variable "endpoints" {
2222
default = {}
2323
}
2424

25+
variable "enable_service_endpoint_lookup" {
26+
description = "Determines whether to look up the service endpoint in the AWS API. If set to false, the `service_endpoint` attribute (usually in the form of `com.amazonaws.<region>.<service>`) must be provided in the `endpoints` map"
27+
type = bool
28+
default = true
29+
}
30+
2531
variable "security_group_ids" {
2632
description = "Default security group IDs to associate with the VPC endpoints"
2733
type = list(string)

0 commit comments

Comments
 (0)