Skip to content

Commit 103fa59

Browse files
Explain region limitations in vpc-endpoints sub-module
1 parent 28d67e2 commit 103fa59

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

modules/vpc-endpoints/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,79 @@ module "endpoints" {
5757
}
5858
```
5959

60+
### Region Support Limitation
61+
62+
When using this sub-module with the [region parameter](https://registry.terraform.io/providers/hashicorp/aws/6.0.0/docs/guides/enhanced-region-support), it will still try to look up the service endpoint in the default region that's set in aws provider configuration. When you have this config:
63+
64+
* aws provider region: us-east-1
65+
* module region: eu-central-1
66+
67+
It leads to an API error as shown:
68+
69+
```plaintext
70+
│ Error: creating EC2 VPC Endpoint (com.amazonaws.us-east-1.s3): operation error EC2: CreateVpcEndpoint, https response error StatusCode: 400, RequestID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, api error InvalidServiceName: The Vpc Endpoint Service 'com.amazonaws.us-east-1.s3' does not exist
71+
72+
│ with module.vpc-endpoints-regions["eu-central-1"].aws_vpc_endpoint.this["s3"],
73+
│ on .terraform/modules/vpc-endpoints-regions/modules/vpc-endpoints/main.tf line 24, in resource "aws_vpc_endpoint" "this":
74+
│ 24: resource "aws_vpc_endpoint" "this" {
75+
```
76+
77+
This happens because the [aws_vpc_endpoint_service](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_endpoint_service) data source used in this sub-module does not support the [region parameter](https://registry.terraform.io/providers/hashicorp/aws/6.0.0/docs/guides/enhanced-region-support#non%E2%80%93region-aware-resources) yet.
78+
79+
As a workaround, we have added the option `enable_service_endpoint_lookup = false` to disable the data source, but you will have to provide fully-qualified service endpoint instead of just the short service name, as shown in the example below.
80+
81+
Before:
82+
83+
```hcl
84+
module "endpoints" {
85+
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
86+
87+
for_each = toset([
88+
"us-east-1",
89+
"eu-west-1",
90+
"eu-central-1",
91+
])
92+
region = each.value
93+
94+
vpc_id = var.regional_vpc_ids[each.value]
95+
security_group_ids = [var.regional_sg_ids[each.value]]
96+
97+
endpoints = {
98+
s3 = {
99+
service = "s3"
100+
# …
101+
}
102+
}
103+
}
104+
```
105+
106+
After:
107+
108+
```hcl
109+
module "endpoints" {
110+
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
111+
112+
for_each = toset([
113+
"us-east-1",
114+
"eu-west-1",
115+
"eu-central-1",
116+
])
117+
region = each.value
118+
119+
vpc_id = var.regional_vpc_ids[each.value]
120+
security_group_ids = [var.regional_sg_ids[each.value]]
121+
122+
enable_service_endpoint_lookup = false # <-- THIS
123+
endpoints = {
124+
s3 = {
125+
service_endpoint = "com.amazonaws.${each.value}.s3" # <-- THIS
126+
service_region = each.value # <-- THIS
127+
# …
128+
}
129+
}
130+
}
131+
```
132+
60133
## Examples
61134

62135
- [Complete-VPC](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete) with VPC Endpoints.

0 commit comments

Comments
 (0)