Skip to content

Commit 8bd0adb

Browse files
committed
chore: updates to support websocket API Gateway
1 parent 3cd47fe commit 8bd0adb

File tree

14 files changed

+94
-57
lines changed

14 files changed

+94
-57
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ repos:
2121
- '--args=--only=terraform_standard_module_structure'
2222
- '--args=--only=terraform_workspace_remote'
2323
- repo: git://github.com/pre-commit/pre-commit-hooks
24-
rev: v3.4.0
24+
rev: v4.0.1
2525
hooks:
2626
- id: check-merge-conflict

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ module "api_gateway" {
9393

9494
| Name | Version |
9595
|------|---------|
96-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.26 |
97-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.3.0 |
96+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
97+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.35 |
9898

9999
## Providers
100100

101101
| Name | Version |
102102
|------|---------|
103-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.3.0 |
103+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 3.57.0 |
104104

105105
## Modules
106106

@@ -123,6 +123,7 @@ No modules.
123123
| Name | Description | Type | Default | Required |
124124
|------|-------------|------|---------|:--------:|
125125
| <a name="input_api_key_selection_expression"></a> [api\_key\_selection\_expression](#input\_api\_key\_selection\_expression) | An API key selection expression. Valid values: $context.authorizer.usageIdentifierKey, $request.header.x-api-key. | `string` | `"$request.header.x-api-key"` | no |
126+
| <a name="input_api_mapping_key"></a> [api\_mapping\_key](#input\_api\_mapping\_key) | The [API mapping key](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-mapping-template-reference.html) | `string` | `null` | no |
126127
| <a name="input_api_version"></a> [api\_version](#input\_api\_version) | A version identifier for the API | `string` | `null` | no |
127128
| <a name="input_body"></a> [body](#input\_body) | An OpenAPI specification that defines the set of routes and integrations to create as part of the HTTP APIs. Supported only for HTTP APIs. | `string` | `null` | no |
128129
| <a name="input_cors_configuration"></a> [cors\_configuration](#input\_cors\_configuration) | The cross-origin resource sharing (CORS) configuration. Applicable for HTTP APIs. | `any` | `{}` | no |
@@ -143,6 +144,7 @@ No modules.
143144
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | The domain name to use for API gateway | `string` | `null` | no |
144145
| <a name="input_domain_name_certificate_arn"></a> [domain\_name\_certificate\_arn](#input\_domain\_name\_certificate\_arn) | The ARN of an AWS-managed certificate that will be used by the endpoint for the domain name | `string` | `null` | no |
145146
| <a name="input_domain_name_tags"></a> [domain\_name\_tags](#input\_domain\_name\_tags) | A mapping of tags to assign to API domain name resource. | `map(string)` | `{}` | no |
147+
| <a name="input_fail_on_warnings"></a> [fail\_on\_warnings](#input\_fail\_on\_warnings) | Whether warnings should return an error while API Gateway is creating or updating the resource using an OpenAPI specification | `bool` | `null` | no |
146148
| <a name="input_integrations"></a> [integrations](#input\_integrations) | Map of API gateway routes with integrations | `map(any)` | `{}` | no |
147149
| <a name="input_mutual_tls_authentication"></a> [mutual\_tls\_authentication](#input\_mutual\_tls\_authentication) | An Amazon S3 URL that specifies the truststore for mutual TLS authentication as well as version, keyed at uri and version | `map(string)` | `{}` | no |
148150
| <a name="input_name"></a> [name](#input\_name) | The name of the API | `string` | `""` | no |
@@ -162,13 +164,14 @@ No modules.
162164
| <a name="output_apigatewayv2_api_arn"></a> [apigatewayv2\_api\_arn](#output\_apigatewayv2\_api\_arn) | The ARN of the API |
163165
| <a name="output_apigatewayv2_api_execution_arn"></a> [apigatewayv2\_api\_execution\_arn](#output\_apigatewayv2\_api\_execution\_arn) | The ARN prefix to be used in an aws\_lambda\_permission's source\_arn attribute or in an aws\_iam\_policy to authorize access to the @connections API. |
164166
| <a name="output_apigatewayv2_api_id"></a> [apigatewayv2\_api\_id](#output\_apigatewayv2\_api\_id) | The API identifier |
165-
| <a name="output_apigatewayv2_api_mapping_id"></a> [apigatewayv2\_api\_mapping\_id](#output\_apigatewayv2\_api\_mapping\_id) | The API mapping identifier. |
167+
| <a name="output_apigatewayv2_api_mapping_id"></a> [apigatewayv2\_api\_mapping\_id](#output\_apigatewayv2\_api\_mapping\_id) | The API mapping identifier |
166168
| <a name="output_apigatewayv2_domain_name_api_mapping_selection_expression"></a> [apigatewayv2\_domain\_name\_api\_mapping\_selection\_expression](#output\_apigatewayv2\_domain\_name\_api\_mapping\_selection\_expression) | The API mapping selection expression for the domain name |
167169
| <a name="output_apigatewayv2_domain_name_arn"></a> [apigatewayv2\_domain\_name\_arn](#output\_apigatewayv2\_domain\_name\_arn) | The ARN of the domain name |
168170
| <a name="output_apigatewayv2_domain_name_configuration"></a> [apigatewayv2\_domain\_name\_configuration](#output\_apigatewayv2\_domain\_name\_configuration) | The domain name configuration |
169171
| <a name="output_apigatewayv2_domain_name_hosted_zone_id"></a> [apigatewayv2\_domain\_name\_hosted\_zone\_id](#output\_apigatewayv2\_domain\_name\_hosted\_zone\_id) | The Amazon Route 53 Hosted Zone ID of the endpoint |
170172
| <a name="output_apigatewayv2_domain_name_id"></a> [apigatewayv2\_domain\_name\_id](#output\_apigatewayv2\_domain\_name\_id) | The domain name identifier |
171173
| <a name="output_apigatewayv2_domain_name_target_domain_name"></a> [apigatewayv2\_domain\_name\_target\_domain\_name](#output\_apigatewayv2\_domain\_name\_target\_domain\_name) | The target domain name |
174+
| <a name="output_apigatewayv2_route"></a> [apigatewayv2\_route](#output\_apigatewayv2\_route) | Map containing the routes created and their attributes |
172175
| <a name="output_apigatewayv2_vpc_link_arn"></a> [apigatewayv2\_vpc\_link\_arn](#output\_apigatewayv2\_vpc\_link\_arn) | The map of VPC Link ARNs |
173176
| <a name="output_apigatewayv2_vpc_link_id"></a> [apigatewayv2\_vpc\_link\_id](#output\_apigatewayv2\_vpc\_link\_id) | The map of VPC Link identifiers |
174177
| <a name="output_default_apigatewayv2_stage_arn"></a> [default\_apigatewayv2\_stage\_arn](#output\_default\_apigatewayv2\_stage\_arn) | The default stage ARN |

examples/complete-http/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Note that this example may create resources which cost money. Run `terraform des
2121
| Name | Version |
2222
|------|---------|
2323
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
24-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.59 |
24+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.35 |
2525
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
2626
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2727
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 3.1 |
@@ -30,17 +30,17 @@ Note that this example may create resources which cost money. Run `terraform des
3030

3131
| Name | Version |
3232
|------|---------|
33-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.59 |
34-
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
35-
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
36-
| <a name="provider_tls"></a> [tls](#provider\_tls) | >= 3.1 |
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 3.57.0 |
34+
| <a name="provider_null"></a> [null](#provider\_null) | 3.1.0 |
35+
| <a name="provider_random"></a> [random](#provider\_random) | 3.1.0 |
36+
| <a name="provider_tls"></a> [tls](#provider\_tls) | 3.1.0 |
3737

3838
## Modules
3939

4040
| Name | Source | Version |
4141
|------|--------|---------|
4242
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | ~> 3.0 |
43-
| <a name="module_api_gateway"></a> [api\_gateway](#module\_api\_gateway) | ../../ | |
43+
| <a name="module_api_gateway"></a> [api\_gateway](#module\_api\_gateway) | ../../ | n/a |
4444
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | terraform-aws-modules/lambda/aws | ~> 2.0 |
4545
| <a name="module_step_function"></a> [step\_function](#module\_step\_function) | terraform-aws-modules/step-functions/aws | ~> 2.0 |
4646

@@ -62,7 +62,9 @@ Note that this example may create resources which cost money. Run `terraform des
6262

6363
## Inputs
6464

65-
No inputs.
65+
| Name | Description | Type | Default | Required |
66+
|------|-------------|------|---------|:--------:|
67+
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | Custom domain name to use on API Gateway endpoint | `string` | n/a | yes |
6668

6769
## Outputs
6870

@@ -74,6 +76,7 @@ No inputs.
7476
| <a name="output_apigatewayv2_domain_name_configuration"></a> [apigatewayv2\_domain\_name\_configuration](#output\_apigatewayv2\_domain\_name\_configuration) | The domain name configuration |
7577
| <a name="output_apigatewayv2_domain_name_id"></a> [apigatewayv2\_domain\_name\_id](#output\_apigatewayv2\_domain\_name\_id) | The domain name identifier |
7678
| <a name="output_apigatewayv2_hosted_zone_id"></a> [apigatewayv2\_hosted\_zone\_id](#output\_apigatewayv2\_hosted\_zone\_id) | The Amazon Route 53 Hosted Zone ID of the endpoint |
79+
| <a name="output_apigatewayv2_route"></a> [apigatewayv2\_route](#output\_apigatewayv2\_route) | Map containing the routes created and their attributes |
7780
| <a name="output_apigatewayv2_target_domain_name"></a> [apigatewayv2\_target\_domain\_name](#output\_apigatewayv2\_target\_domain\_name) | The target domain name |
7881
| <a name="output_lambda_cloudwatch_log_group_arn"></a> [lambda\_cloudwatch\_log\_group\_arn](#output\_lambda\_cloudwatch\_log\_group\_arn) | The ARN of the Cloudwatch Log Group |
7982
| <a name="output_lambda_function_arn"></a> [lambda\_function\_arn](#output\_lambda\_function\_arn) | The ARN of the Lambda Function |

examples/complete-http/main.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ provider "aws" {
1212
}
1313

1414
locals {
15-
domain_name = "terraform-aws-modules.modules.tf" # trimsuffix(data.aws_route53_zone.this.name, ".")
16-
subdomain = "complete-http"
15+
subdomain = "complete-http"
1716
}
1817

1918
###################
@@ -38,7 +37,7 @@ module "api_gateway" {
3837
truststore_version = aws_s3_bucket_object.truststore.version_id
3938
}
4039

41-
domain_name = local.domain_name
40+
domain_name = var.domain_name
4241
domain_name_certificate_arn = module.acm.acm_certificate_arn
4342

4443
default_stage_access_log_destination_arn = aws_cloudwatch_log_group.logs.arn
@@ -82,7 +81,7 @@ module "api_gateway" {
8281
"$default" = {
8382
lambda_arn = module.lambda_function.lambda_function_arn
8483
tls_config = jsonencode({
85-
server_name_to_verify = local.domain_name
84+
server_name_to_verify = var.domain_name
8685
})
8786
}
8887

@@ -102,16 +101,16 @@ module "api_gateway" {
102101
######
103102

104103
data "aws_route53_zone" "this" {
105-
name = local.domain_name
104+
name = var.domain_name
106105
}
107106

108107
module "acm" {
109108
source = "terraform-aws-modules/acm/aws"
110109
version = "~> 3.0"
111110

112-
domain_name = local.domain_name
111+
domain_name = var.domain_name
113112
zone_id = data.aws_route53_zone.this.id
114-
subject_alternative_names = ["${local.subdomain}.${local.domain_name}"]
113+
subject_alternative_names = ["${local.subdomain}.${var.domain_name}"]
115114
}
116115

117116
##########

examples/complete-http/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ output "apigatewayv2_hosted_zone_id" {
125125
value = module.api_gateway.apigatewayv2_domain_name_hosted_zone_id
126126
}
127127

128+
output "apigatewayv2_route" {
129+
description = "Map containing the routes created and their attributes"
130+
value = module.api_gateway.apigatewayv2_route
131+
}
132+
128133
# Route53 record
129134
output "api_fqdn" {
130135
description = "List of Route53 records"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
domain_name="yourdomain.com"

examples/complete-http/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "domain_name" {
2+
description = "Custom domain name to use on API Gateway endpoint"
3+
type = string
4+
}

examples/complete-http/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_version = ">= 0.13.1"
33

44
required_providers {
5-
aws = ">= 2.59"
5+
aws = ">= 3.35"
66
random = ">= 2.0"
77
null = ">= 2.0"
88
tls = ">= 3.1"

examples/vpc-link-http/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ Note that this example may create resources which cost money. Run `terraform des
2121
| Name | Version |
2222
|------|---------|
2323
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
24-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.59 |
24+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.35 |
2525
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
2626
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2727

2828
## Providers
2929

3030
| Name | Version |
3131
|------|---------|
32-
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
33-
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
32+
| <a name="provider_null"></a> [null](#provider\_null) | 3.1.0 |
33+
| <a name="provider_random"></a> [random](#provider\_random) | 3.1.0 |
3434

3535
## Modules
3636

3737
| Name | Source | Version |
3838
|------|--------|---------|
3939
| <a name="module_alb"></a> [alb](#module\_alb) | terraform-aws-modules/alb/aws | ~> 6.0 |
4040
| <a name="module_alb_security_group"></a> [alb\_security\_group](#module\_alb\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
41-
| <a name="module_api_gateway"></a> [api\_gateway](#module\_api\_gateway) | ../../ | |
41+
| <a name="module_api_gateway"></a> [api\_gateway](#module\_api\_gateway) | ../../ | n/a |
4242
| <a name="module_api_gateway_security_group"></a> [api\_gateway\_security\_group](#module\_api\_gateway\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
4343
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | terraform-aws-modules/lambda/aws | ~> 2.0 |
4444
| <a name="module_lambda_security_group"></a> [lambda\_security\_group](#module\_lambda\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |

examples/vpc-link-http/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_version = ">= 0.13.1"
33

44
required_providers {
5-
aws = ">= 2.59"
5+
aws = ">= 3.35"
66
random = ">= 2.0"
77
null = ">= 2.0"
88
}

main.tf

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ resource "aws_apigatewayv2_api" "this" {
66
description = var.description
77
protocol_type = var.protocol_type
88
version = var.api_version
9-
body = var.body
9+
body = var.protocol_type == "HTTP" ? var.body : null
1010

1111
route_selection_expression = var.route_selection_expression
12-
api_key_selection_expression = var.api_key_selection_expression
12+
api_key_selection_expression = var.protocol_type == "WEBSOCKET" ? var.api_key_selection_expression : null
1313
disable_execute_api_endpoint = var.disable_execute_api_endpoint
14+
fail_on_warnings = var.protocol_type == "HTTP" ? var.fail_on_warnings : null
1415

1516
/* Start of quick create */
16-
route_key = var.route_key
17-
credentials_arn = var.credentials_arn
18-
target = var.target
17+
route_key = var.protocol_type == "HTTP" ? var.route_key : null
18+
credentials_arn = var.protocol_type == "HTTP" ? var.credentials_arn : null
19+
target = var.protocol_type == "HTTP" ? var.target : null
1920
/* End of quick create */
2021

2122
dynamic "cors_configuration" {
22-
for_each = length(keys(var.cors_configuration)) == 0 ? [] : [var.cors_configuration]
23+
for_each = var.protocol_type != "HTTP" || length(keys(var.cors_configuration)) == 0 ? [] : [var.cors_configuration]
2324

2425
content {
2526
allow_credentials = lookup(cors_configuration.value, "allow_credentials", null)
@@ -84,34 +85,38 @@ resource "aws_apigatewayv2_stage" "default" {
8485
}
8586
}
8687

87-
# # bug - https://github.com/terraform-providers/terraform-provider-aws/issues/12893
88-
# dynamic "route_settings" {
89-
# for_each = var.create_routes_and_integrations ? var.integrations : {}
90-
# content {
91-
# route_key = route_settings.key
92-
# data_trace_enabled = lookup(route_settings.value, "data_trace_enabled", null)
93-
# detailed_metrics_enabled = lookup(route_settings.value, "detailed_metrics_enabled", null)
94-
# logging_level = lookup(route_settings.value, "logging_level", null) # Error: error updating API Gateway v2 stage ($default): BadRequestException: Execution logs are not supported on protocolType HTTP
95-
# throttling_burst_limit = lookup(route_settings.value, "throttling_burst_limit", null)
96-
# throttling_rate_limit = lookup(route_settings.value, "throttling_rate_limit", null)
97-
# }
98-
# }
88+
dynamic "route_settings" {
89+
for_each = var.create_routes_and_integrations ? var.integrations : {}
90+
content {
91+
route_key = route_settings.key
92+
data_trace_enabled = lookup(route_settings.value, "data_trace_enabled", null)
93+
detailed_metrics_enabled = lookup(route_settings.value, "detailed_metrics_enabled", null)
94+
logging_level = lookup(route_settings.value, "logging_level", null) # Error: error updating API Gateway v2 stage ($default): BadRequestException: Execution logs are not supported on protocolType HTTP
95+
throttling_burst_limit = lookup(route_settings.value, "throttling_burst_limit", null)
96+
throttling_rate_limit = lookup(route_settings.value, "throttling_rate_limit", null)
97+
}
98+
}
9999

100100
tags = merge(var.default_stage_tags, var.tags)
101101

102102
# Bug in terraform-aws-provider with perpetual diff
103103
lifecycle {
104104
ignore_changes = [deployment_id]
105105
}
106+
107+
depends_on = [
108+
aws_apigatewayv2_route.this
109+
]
106110
}
107111

108112
# Default API mapping
109113
resource "aws_apigatewayv2_api_mapping" "this" {
110114
count = var.create && var.create_api_domain_name && var.create_default_stage && var.create_default_stage_api_mapping ? 1 : 0
111115

112-
api_id = aws_apigatewayv2_api.this[0].id
113-
domain_name = aws_apigatewayv2_domain_name.this[0].id
114-
stage = aws_apigatewayv2_stage.default[0].id
116+
api_id = aws_apigatewayv2_api.this[0].id
117+
domain_name = aws_apigatewayv2_domain_name.this[0].id
118+
stage = aws_apigatewayv2_stage.default[0].id
119+
api_mapping_key = var.api_mapping_key
115120
}
116121

117122
# Routes and integrations
@@ -122,16 +127,22 @@ resource "aws_apigatewayv2_route" "this" {
122127
route_key = each.key
123128

124129
api_key_required = lookup(each.value, "api_key_required", null)
130+
authorization_scopes = try(lookup(each.value, "authorization_scopes", []), [])
125131
authorization_type = lookup(each.value, "authorization_type", "NONE")
126132
authorizer_id = lookup(each.value, "authorizer_id", null)
127133
model_selection_expression = lookup(each.value, "model_selection_expression", null)
128134
operation_name = lookup(each.value, "operation_name", null)
135+
request_models = try(lookup(each.value, "request_models", {}), {})
129136
route_response_selection_expression = lookup(each.value, "route_response_selection_expression", null)
130137
target = "integrations/${aws_apigatewayv2_integration.this[each.key].id}"
131138

132-
# Not sure what structure is allowed for these arguments...
133-
# authorization_scopes = lookup(each.value, "authorization_scopes", null)
134-
# request_models = lookup(each.value, "request_models", null)
139+
dynamic "request_parameter" {
140+
for_each = lookup(each.value, "request_parameter", null) != null ? each.value.request_parameter : {}
141+
content {
142+
request_parameter_key = request_parameter.value.request_parameter_key
143+
required = request_parameter.value.required
144+
}
145+
}
135146
}
136147

137148
resource "aws_apigatewayv2_integration" "this" {

outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ output "apigatewayv2_domain_name_hosted_zone_id" {
7777

7878
# api mapping
7979
output "apigatewayv2_api_mapping_id" {
80-
description = "The API mapping identifier."
80+
description = "The API mapping identifier"
8181
value = element(concat(aws_apigatewayv2_api_mapping.this.*.id, [""]), 0)
8282
}
8383

8484
# route
85-
# output "apigatewayv2_route_id" {
86-
# description = "The default route identifier."
87-
# value = element(concat(aws_apigatewayv2_route.this.*.id, [""]), 0)
88-
# }
85+
output "apigatewayv2_route" {
86+
description = "Map containing the routes created and their attributes"
87+
value = aws_apigatewayv2_route.this
88+
}
8989

9090
# VPC link
9191
output "apigatewayv2_vpc_link_id" {

0 commit comments

Comments
 (0)