Skip to content

Commit ccea02c

Browse files
committed
feat: Add support for region resource level argument
1 parent 2cb86af commit ccea02c

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ module "api_gateway" {
198198

199199
| Name | Source | Version |
200200
|------|--------|---------|
201-
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | 5.0.1 |
201+
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | 6.1.1 |
202202

203203
## Resources
204204

@@ -249,6 +249,7 @@ module "api_gateway" {
249249
| <a name="input_name"></a> [name](#input\_name) | The name of the API. Must be less than or equal to 128 characters in length | `string` | `""` | no |
250250
| <a name="input_private_zone"></a> [private\_zone](#input\_private\_zone) | Indicates the hosted zone being looked up is private. Certificate validation will fail if this is set to true. | `bool` | `false` | no |
251251
| <a name="input_protocol_type"></a> [protocol\_type](#input\_protocol\_type) | The API protocol. Valid values: `HTTP`, `WEBSOCKET` | `string` | `"HTTP"` | no |
252+
| <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 |
252253
| <a name="input_route_key"></a> [route\_key](#input\_route\_key) | Part of quick create. Specifies any route key. Applicable for HTTP APIs | `string` | `null` | no |
253254
| <a name="input_route_selection_expression"></a> [route\_selection\_expression](#input\_route\_selection\_expression) | The route selection expression for the API. Defaults to `$request.method $request.path` | `string` | `null` | no |
254255
| <a name="input_routes"></a> [routes](#input\_routes) | Map of API gateway routes with integrations | <pre>map(object({<br/> # Route<br/> authorizer_key = optional(string)<br/> api_key_required = optional(bool)<br/> authorization_scopes = optional(list(string), [])<br/> authorization_type = optional(string)<br/> authorizer_id = optional(string)<br/> model_selection_expression = optional(string)<br/> operation_name = optional(string)<br/> request_models = optional(map(string), {})<br/> request_parameter = optional(object({<br/> request_parameter_key = optional(string)<br/> required = optional(bool, false)<br/> }), {})<br/> route_response_selection_expression = optional(string)<br/><br/> # Route settings<br/> data_trace_enabled = optional(bool)<br/> detailed_metrics_enabled = optional(bool)<br/> logging_level = optional(string)<br/> throttling_burst_limit = optional(number)<br/> throttling_rate_limit = optional(number)<br/><br/> # Stage - Route response<br/> route_response = optional(object({<br/> create = optional(bool, false)<br/> model_selection_expression = optional(string)<br/> response_models = optional(map(string))<br/> route_response_key = optional(string, "$default")<br/> }), {})<br/><br/> # Integration<br/> integration = object({<br/> connection_id = optional(string)<br/> vpc_link_key = optional(string)<br/> connection_type = optional(string)<br/> content_handling_strategy = optional(string)<br/> credentials_arn = optional(string)<br/> description = optional(string)<br/> method = optional(string)<br/> subtype = optional(string)<br/> type = optional(string, "AWS_PROXY")<br/> uri = optional(string)<br/> passthrough_behavior = optional(string)<br/> payload_format_version = optional(string)<br/> request_parameters = optional(map(string), {})<br/> request_templates = optional(map(string), {})<br/> response_parameters = optional(list(object({<br/> mappings = map(string)<br/> status_code = string<br/> })))<br/> template_selection_expression = optional(string)<br/> timeout_milliseconds = optional(number)<br/> tls_config = optional(object({<br/> server_name_to_verify = optional(string)<br/> }))<br/><br/> # Integration Response<br/> response = optional(object({<br/> content_handling_strategy = optional(string)<br/> integration_response_key = optional(string)<br/> response_templates = optional(map(string))<br/> template_selection_expression = optional(string)<br/> }), {})<br/> })<br/> }))</pre> | `{}` | no |

docs/UPGRADE-6.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If you find a bug, please open an issue with supporting configuration to reprodu
1212

1313
### Added
1414

15-
-
15+
- Support for `region` parameter to specify the AWS region for the resources created if different from the provider region.
1616

1717
### Modified
1818

main.tf

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ locals {
1212
resource "aws_apigatewayv2_api" "this" {
1313
count = var.create ? 1 : 0
1414

15+
region = var.region
16+
1517
api_key_selection_expression = local.is_websocket ? var.api_key_selection_expression : null
1618
body = local.is_http ? var.body : null
1719

@@ -54,6 +56,8 @@ resource "aws_apigatewayv2_api" "this" {
5456
resource "aws_apigatewayv2_authorizer" "this" {
5557
for_each = { for k, v in var.authorizers : k => v if var.create }
5658

59+
region = var.region
60+
5761
api_id = aws_apigatewayv2_api.this[0].id
5862

5963
authorizer_credentials_arn = each.value.authorizer_credentials_arn
@@ -87,6 +91,8 @@ locals {
8791
resource "aws_apigatewayv2_domain_name" "this" {
8892
count = local.create_domain_name ? 1 : 0
8993

94+
region = var.region
95+
9096
domain_name = var.domain_name
9197

9298
domain_name_configuration {
@@ -112,6 +118,8 @@ resource "aws_apigatewayv2_domain_name" "this" {
112118
resource "aws_apigatewayv2_api_mapping" "this" {
113119
count = local.create_domain_name && local.create_stage ? 1 : 0
114120

121+
region = var.region
122+
115123
api_id = aws_apigatewayv2_api.this[0].id
116124
api_mapping_key = var.api_mapping_key
117125
domain_name = aws_apigatewayv2_domain_name.this[0].id
@@ -166,7 +174,9 @@ locals {
166174

167175
module "acm" {
168176
source = "terraform-aws-modules/acm/aws"
169-
version = "5.0.1"
177+
version = "6.1.1" # TODO - https://github.com/terraform-aws-modules/terraform-aws-acm/pull/167
178+
179+
region = var.region
170180

171181
create_certificate = local.create_domain_name && var.create_domain_records && local.create_certificate
172182

@@ -186,6 +196,8 @@ module "acm" {
186196
resource "aws_apigatewayv2_route" "this" {
187197
for_each = { for k, v in var.routes : k => v if local.create_routes_and_integrations }
188198

199+
region = var.region
200+
189201
api_id = aws_apigatewayv2_api.this[0].id
190202

191203
api_key_required = local.is_websocket ? each.value.api_key_required : null
@@ -217,6 +229,8 @@ resource "aws_apigatewayv2_route" "this" {
217229
resource "aws_apigatewayv2_route_response" "this" {
218230
for_each = { for k, v in var.routes : k => v if local.create_routes_and_integrations && coalesce(v.route_response.create, false) }
219231

232+
region = var.region
233+
220234
api_id = aws_apigatewayv2_api.this[0].id
221235
model_selection_expression = each.value.route_response.model_selection_expression
222236
response_models = each.value.route_response.response_models
@@ -231,8 +245,9 @@ resource "aws_apigatewayv2_route_response" "this" {
231245
resource "aws_apigatewayv2_integration" "this" {
232246
for_each = { for k, v in var.routes : k => v.integration if local.create_routes_and_integrations }
233247

234-
api_id = aws_apigatewayv2_api.this[0].id
248+
region = var.region
235249

250+
api_id = aws_apigatewayv2_api.this[0].id
236251
connection_id = try(aws_apigatewayv2_vpc_link.this[each.value.vpc_link_key].id, each.value.connection_id)
237252
connection_type = each.value.connection_type
238253
content_handling_strategy = each.value.content_handling_strategy
@@ -279,6 +294,8 @@ resource "aws_apigatewayv2_integration" "this" {
279294
resource "aws_apigatewayv2_integration_response" "this" {
280295
for_each = { for k, v in var.routes : k => v.integration if local.create_routes_and_integrations && v.integration.response.integration_response_key != null }
281296

297+
region = var.region
298+
282299
api_id = aws_apigatewayv2_api.this[0].id
283300
integration_id = aws_apigatewayv2_integration.this[each.key].id
284301

@@ -324,6 +341,8 @@ locals {
324341
resource "aws_apigatewayv2_stage" "this" {
325342
count = local.create_stage ? 1 : 0
326343

344+
region = var.region
345+
327346
api_id = aws_apigatewayv2_api.this[0].id
328347

329348
dynamic "access_log_settings" {
@@ -383,6 +402,8 @@ resource "aws_apigatewayv2_stage" "this" {
383402
resource "aws_apigatewayv2_deployment" "this" {
384403
count = local.create_stage && var.deploy_stage && !local.is_http ? 1 : 0
385404

405+
region = var.region
406+
386407
api_id = aws_apigatewayv2_api.this[0].id
387408
description = var.description
388409

@@ -414,6 +435,8 @@ resource "aws_apigatewayv2_deployment" "this" {
414435
resource "aws_cloudwatch_log_group" "this" {
415436
for_each = { for k, v in { "this" = var.stage_access_log_settings } : k => v if local.create_stage && v != null && try(v.create_log_group, true) }
416437

438+
region = var.region
439+
417440
name = coalesce(each.value.log_group_name, "/aws/apigateway/${var.name}/${replace(var.stage_name, "$", "")}")
418441
retention_in_days = each.value.log_group_retention_in_days
419442
kms_key_id = each.value.log_group_kms_key_id
@@ -430,6 +453,8 @@ resource "aws_cloudwatch_log_group" "this" {
430453
resource "aws_apigatewayv2_vpc_link" "this" {
431454
for_each = { for k, v in var.vpc_links : k => v if var.create }
432455

456+
region = var.region
457+
433458
name = coalesce(each.value.name, each.key)
434459
security_group_ids = each.value.security_group_ids
435460
subnet_ids = each.value.subnet_ids

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variable "create" {
44
default = true
55
}
66

7+
variable "region" {
8+
description = "Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration"
9+
type = string
10+
default = null
11+
}
12+
713
variable "tags" {
814
description = "A mapping of tags to assign to API gateway resources"
915
type = map(string)

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module "wrapper" {
2929
name = try(each.value.name, var.defaults.name, "")
3030
private_zone = try(each.value.private_zone, var.defaults.private_zone, false)
3131
protocol_type = try(each.value.protocol_type, var.defaults.protocol_type, "HTTP")
32+
region = try(each.value.region, var.defaults.region, null)
3233
route_key = try(each.value.route_key, var.defaults.route_key, null)
3334
route_selection_expression = try(each.value.route_selection_expression, var.defaults.route_selection_expression, null)
3435
routes = try(each.value.routes, var.defaults.routes, {})

0 commit comments

Comments
 (0)