Skip to content

Commit a13ef33

Browse files
feat: Enable route_settings in default stage (#80)
Co-authored-by: Anton Babenko <[email protected]>
1 parent ea566fc commit a13ef33

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

examples/complete-http/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Note that this example may create resources which cost money. Run `terraform des
4141
|------|--------|---------|
4242
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | ~> 3.0 |
4343
| <a name="module_api_gateway"></a> [api\_gateway](#module\_api\_gateway) | ../../ | n/a |
44-
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | terraform-aws-modules/lambda/aws | ~> 2.0 |
44+
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | terraform-aws-modules/lambda/aws | ~> 3.0 |
4545
| <a name="module_step_function"></a> [step\_function](#module\_step\_function) | terraform-aws-modules/step-functions/aws | ~> 2.0 |
4646

4747
## Resources
@@ -53,7 +53,7 @@ Note that this example may create resources which cost money. Run `terraform des
5353
| [aws_cognito_user_pool.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool) | resource |
5454
| [aws_route53_record.api](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
5555
| [aws_s3_bucket.truststore](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
56-
| [aws_s3_bucket_object.truststore](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object) | resource |
56+
| [aws_s3_object.truststore](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
5757
| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
5858
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
5959
| [tls_private_key.private_key](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |

examples/complete-http/main.tf

+13-8
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ module "api_gateway" {
3434
}
3535

3636
mutual_tls_authentication = {
37-
truststore_uri = "s3://${aws_s3_bucket.truststore.bucket}/${aws_s3_bucket_object.truststore.id}"
38-
truststore_version = aws_s3_bucket_object.truststore.version_id
37+
truststore_uri = "s3://${aws_s3_bucket.truststore.bucket}/${aws_s3_object.truststore.id}"
38+
truststore_version = aws_s3_object.truststore.version_id
3939
}
4040

4141
domain_name = local.domain_name
@@ -69,10 +69,13 @@ module "api_gateway" {
6969
}
7070

7171
"GET /some-route" = {
72-
lambda_arn = module.lambda_function.lambda_function_arn
73-
payload_format_version = "2.0"
74-
authorization_type = "JWT"
75-
authorizer_id = aws_apigatewayv2_authorizer.some_authorizer.id
72+
lambda_arn = module.lambda_function.lambda_function_arn
73+
payload_format_version = "2.0"
74+
authorization_type = "JWT"
75+
authorizer_id = aws_apigatewayv2_authorizer.some_authorizer.id
76+
throttling_rate_limit = 80
77+
throttling_burst_limit = 40
78+
detailed_metrics_enabled = true
7679
}
7780

7881
"GET /some-route-with-authorizer" = {
@@ -84,13 +87,15 @@ module "api_gateway" {
8487
"GET /some-route-with-authorizer-and-scope" = {
8588
lambda_arn = module.lambda_function.lambda_function_arn
8689
payload_format_version = "2.0"
90+
authorization_type = "JWT"
8791
authorizer_key = "cognito"
8892
authorization_scopes = "tf/something.relevant.read,tf/something.relevant.write" # Should comply with the resource server configuration part of the cognito user pool
8993
}
9094

9195
"GET /some-route-with-authorizer-and-different-scope" = {
9296
lambda_arn = module.lambda_function.lambda_function_arn
9397
payload_format_version = "2.0"
98+
authorization_type = "JWT"
9499
authorizer_key = "cognito"
95100
authorization_scopes = "tf/something.relevant.write" # Should comply with the resource server configuration part of the cognito user pool
96101
}
@@ -263,7 +268,7 @@ resource "null_resource" "download_package" {
263268

264269
module "lambda_function" {
265270
source = "terraform-aws-modules/lambda/aws"
266-
version = "~> 2.0"
271+
version = "~> 3.0"
267272

268273
function_name = "${random_pet.this.id}-lambda"
269274
description = "My awesome lambda function"
@@ -292,7 +297,7 @@ resource "aws_s3_bucket" "truststore" {
292297
# acl = "private"
293298
}
294299

295-
resource "aws_s3_bucket_object" "truststore" {
300+
resource "aws_s3_object" "truststore" {
296301
bucket = aws_s3_bucket.truststore.bucket
297302
key = "truststore.pem"
298303
server_side_encryption = "AES256"

main.tf

+16-14
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,28 @@ resource "aws_apigatewayv2_stage" "default" {
8080
for_each = length(keys(var.default_route_settings)) == 0 ? [] : [var.default_route_settings]
8181

8282
content {
83-
data_trace_enabled = try(default_route_settings.value.data_trace_enabled, false)
83+
data_trace_enabled = try(default_route_settings.value.data_trace_enabled, false) # supported in Websocket APIGateway only
84+
logging_level = try(default_route_settings.value.logging_level, null) # supported in Websocket APIGateway only
85+
8486
detailed_metrics_enabled = try(default_route_settings.value.detailed_metrics_enabled, false)
85-
logging_level = try(default_route_settings.value.logging_level, null)
8687
throttling_burst_limit = try(default_route_settings.value.throttling_burst_limit, null)
8788
throttling_rate_limit = try(default_route_settings.value.throttling_rate_limit, null)
8889
}
8990
}
9091

91-
# # bug - https://github.com/terraform-providers/terraform-provider-aws/issues/12893
92-
# dynamic "route_settings" {
93-
# for_each = var.create_routes_and_integrations ? var.integrations : {}
94-
# content {
95-
# route_key = route_settings.key
96-
# data_trace_enabled = try(route_settings.value.data_trace_enabled, null)
97-
# detailed_metrics_enabled = try(route_settings.value.detailed_metrics_enabled, null)
98-
# logging_level = try(route_settings.value.logging_level, null) # Error: error updating API Gateway v2 stage ($default): BadRequestException: Execution logs are not supported on protocolType HTTP
99-
# throttling_burst_limit = try(route_settings.value.throttling_burst_limit, null)
100-
# throttling_rate_limit = try(route_settings.value.throttling_rate_limit, null)
101-
# }
102-
# }
92+
dynamic "route_settings" {
93+
for_each = { for k, v in var.integrations : k => v if var.create_routes_and_integrations && length(setintersection(["data_trace_enabled", "detailed_metrics_enabled", "logging_level", "throttling_burst_limit", "throttling_rate_limit"], keys(v))) > 0 }
94+
95+
content {
96+
route_key = route_settings.key
97+
data_trace_enabled = try(route_settings.value.data_trace_enabled, var.default_route_settings["data_trace_enabled"], false) # supported in Websocket APIGateway only
98+
logging_level = try(route_settings.value.logging_level, var.default_route_settings["logging_level"], null) # supported in Websocket APIGateway only
99+
100+
detailed_metrics_enabled = try(route_settings.value.detailed_metrics_enabled, var.default_route_settings["detailed_metrics_enabled"], false)
101+
throttling_burst_limit = try(route_settings.value.throttling_burst_limit, var.default_route_settings["throttling_burst_limit"], null)
102+
throttling_rate_limit = try(route_settings.value.throttling_rate_limit, var.default_route_settings["throttling_rate_limit"], null)
103+
}
104+
}
103105

104106
tags = merge(var.default_stage_tags, var.tags)
105107

0 commit comments

Comments
 (0)