@@ -22,12 +22,12 @@ resource "aws_apigatewayv2_api" "this" {
2222 for_each = length (keys (var. cors_configuration )) == 0 ? [] : [var . cors_configuration ]
2323
2424 content {
25- allow_credentials = lookup (cors_configuration. value , " allow_credentials" , null )
26- allow_headers = lookup (cors_configuration. value , " allow_headers" , null )
27- allow_methods = lookup (cors_configuration. value , " allow_methods" , null )
28- allow_origins = lookup (cors_configuration. value , " allow_origins" , null )
29- expose_headers = lookup (cors_configuration. value , " expose_headers" , null )
30- max_age = lookup (cors_configuration. value , " max_age" , null )
25+ allow_credentials = try (cors_configuration. value . allow_credentials , null )
26+ allow_headers = try (cors_configuration. value . allow_headers , null )
27+ allow_methods = try (cors_configuration. value . allow_methods , null )
28+ allow_origins = try (cors_configuration. value . allow_origins , null )
29+ expose_headers = try (cors_configuration. value . expose_headers , null )
30+ max_age = try (cors_configuration. value . max_age , null )
3131 }
3232 }
3333
@@ -48,9 +48,10 @@ resource "aws_apigatewayv2_domain_name" "this" {
4848
4949 dynamic "mutual_tls_authentication" {
5050 for_each = length (keys (var. mutual_tls_authentication )) == 0 ? [] : [var . mutual_tls_authentication ]
51+
5152 content {
5253 truststore_uri = mutual_tls_authentication. value . truststore_uri
53- truststore_version = lookup (mutual_tls_authentication. value , " truststore_version" , null )
54+ truststore_version = try (mutual_tls_authentication. value . truststore_version , null )
5455 }
5556 }
5657
@@ -67,6 +68,7 @@ resource "aws_apigatewayv2_stage" "default" {
6768
6869 dynamic "access_log_settings" {
6970 for_each = var. default_stage_access_log_destination_arn != null && var. default_stage_access_log_format != null ? [true ] : []
71+
7072 content {
7173 destination_arn = var. default_stage_access_log_destination_arn
7274 format = var. default_stage_access_log_format
@@ -75,12 +77,13 @@ resource "aws_apigatewayv2_stage" "default" {
7577
7678 dynamic "default_route_settings" {
7779 for_each = length (keys (var. default_route_settings )) == 0 ? [] : [var . default_route_settings ]
80+
7881 content {
79- data_trace_enabled = lookup (default_route_settings. value , " data_trace_enabled" , false )
80- detailed_metrics_enabled = lookup (default_route_settings. value , " detailed_metrics_enabled" , false )
81- logging_level = lookup (default_route_settings. value , " logging_level" , null )
82- throttling_burst_limit = lookup (default_route_settings. value , " throttling_burst_limit" , null )
83- throttling_rate_limit = lookup (default_route_settings. value , " throttling_rate_limit" , null )
82+ data_trace_enabled = try (default_route_settings. value . data_trace_enabled , false )
83+ detailed_metrics_enabled = try (default_route_settings. value . detailed_metrics_enabled , false )
84+ logging_level = try (default_route_settings. value . logging_level , null )
85+ throttling_burst_limit = try (default_route_settings. value . throttling_burst_limit , null )
86+ throttling_rate_limit = try (default_route_settings. value . throttling_rate_limit , null )
8487 }
8588 }
8689
@@ -89,11 +92,11 @@ resource "aws_apigatewayv2_stage" "default" {
8992 # for_each = var.create_routes_and_integrations ? var.integrations : {}
9093 # content {
9194 # 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)
95+ # data_trace_enabled = try (route_settings.value. data_trace_enabled, null)
96+ # detailed_metrics_enabled = try (route_settings.value. detailed_metrics_enabled, null)
97+ # 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
98+ # throttling_burst_limit = try (route_settings.value. throttling_burst_limit, null)
99+ # throttling_rate_limit = try (route_settings.value. throttling_rate_limit, null)
97100 # }
98101 # }
99102
@@ -121,49 +124,51 @@ resource "aws_apigatewayv2_route" "this" {
121124 api_id = aws_apigatewayv2_api. this [0 ]. id
122125 route_key = each. key
123126
124- api_key_required = lookup (each. value , " api_key_required" , null )
125- authorization_type = lookup (each. value , " authorization_type" , " NONE" )
126- authorizer_id = lookup ( each. value , " authorizer_id" , null )
127- model_selection_expression = lookup (each. value , " model_selection_expression" , null )
128- operation_name = lookup (each. value , " operation_name" , null )
129- route_response_selection_expression = lookup (each. value , " route_response_selection_expression" , null )
127+ api_key_required = try (each. value . api_key_required , null )
128+ authorization_type = try (each. value . authorization_type , " NONE" )
129+ authorizer_id = try (aws_apigatewayv2_authorizer . this [ each . value . authorizer_key ] . id , each . value . authorizer_id , null )
130+ model_selection_expression = try (each. value . model_selection_expression , null )
131+ operation_name = try (each. value . operation_name , null )
132+ route_response_selection_expression = try (each. value . route_response_selection_expression , null )
130133 target = " integrations/${ aws_apigatewayv2_integration . this [each . key ]. id } "
131134
132135 # 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)
136+ # authorization_scopes = try (each.value. authorization_scopes, null)
137+ # request_models = try (each.value. request_models, null)
135138}
136139
137140resource "aws_apigatewayv2_integration" "this" {
138141 for_each = var. create && var. create_routes_and_integrations ? var. integrations : {}
139142
140143 api_id = aws_apigatewayv2_api. this [0 ]. id
141- description = lookup (each. value , " description" , null )
144+ description = try (each. value . description , null )
142145
143- integration_type = lookup (each. value , " integration_type" , lookup (each. value , " lambda_arn" , " " ) != " " ? " AWS_PROXY" : " MOCK" )
144- integration_subtype = lookup (each. value , " integration_subtype" , null )
145- integration_method = lookup (each. value , " integration_method" , lookup (each. value , " integration_subtype" , null ) == null ? " POST" : null )
146- integration_uri = lookup (each. value , " lambda_arn" , lookup (each. value , " integration_uri" , null ))
146+ integration_type = try (each. value . integration_type , try (each. value . lambda_arn , " " ) != " " ? " AWS_PROXY" : " MOCK" )
147+ integration_subtype = try (each. value . integration_subtype , null )
148+ integration_method = try (each. value . integration_method , try (each. value . integration_subtype , null ) == null ? " POST" : null )
149+ integration_uri = try (each. value . lambda_arn , try (each. value . integration_uri , null ))
147150
148- connection_type = lookup (each. value , " connection_type" , " INTERNET" )
149- connection_id = try (aws_apigatewayv2_vpc_link. this [each . value [" vpc_link" ]]. id , lookup (each. value , " connection_id" , null ))
151+ connection_type = try (each. value . connection_type , " INTERNET" )
152+ connection_id = try (aws_apigatewayv2_vpc_link. this [each . value [" vpc_link" ]]. id , try (each. value . connection_id , null ))
150153
151- payload_format_version = lookup (each. value , " payload_format_version" , null )
152- timeout_milliseconds = lookup (each. value , " timeout_milliseconds" , null )
153- passthrough_behavior = lookup (each. value , " passthrough_behavior" , null )
154- content_handling_strategy = lookup (each. value , " content_handling_strategy" , null )
155- credentials_arn = lookup (each. value , " credentials_arn" , null )
154+ payload_format_version = try (each. value . payload_format_version , null )
155+ timeout_milliseconds = try (each. value . timeout_milliseconds , null )
156+ passthrough_behavior = try (each. value . passthrough_behavior , null )
157+ content_handling_strategy = try (each. value . content_handling_strategy , null )
158+ credentials_arn = try (each. value . credentials_arn , null )
156159 request_parameters = try (jsondecode (each. value [" request_parameters" ]), each. value [" request_parameters" ], null )
157160
158161 dynamic "tls_config" {
159162 for_each = flatten ([try (jsondecode (each. value [" tls_config" ]), each. value [" tls_config" ], [])])
163+
160164 content {
161165 server_name_to_verify = tls_config. value [" server_name_to_verify" ]
162166 }
163167 }
164168
165169 dynamic "response_parameters" {
166170 for_each = flatten ([try (jsondecode (each. value [" response_parameters" ]), each. value [" response_parameters" ], [])])
171+
167172 content {
168173 status_code = response_parameters. value [" status_code" ]
169174 mappings = response_parameters. value [" mappings" ]
@@ -175,13 +180,35 @@ resource "aws_apigatewayv2_integration" "this" {
175180 }
176181}
177182
183+ # Authorizers
184+ resource "aws_apigatewayv2_authorizer" "this" {
185+ for_each = var. create && var. create_routes_and_integrations ? var. authorizers : {}
186+
187+ api_id = aws_apigatewayv2_api. this [0 ]. id
188+
189+ authorizer_type = try (each. value . authorizer_type , null )
190+ identity_sources = try (flatten ([each . value . identity_sources ]), null )
191+ name = try (each. value . name , null )
192+ authorizer_uri = try (each. value . authorizer_uri , null )
193+ authorizer_payload_format_version = try (each. value . authorizer_payload_format_version , null )
194+
195+ dynamic "jwt_configuration" {
196+ for_each = length (try (each. value . audience , [each . value . issuer ], [])) > 0 ? [true ] : []
197+
198+ content {
199+ audience = try (each. value . audience , null )
200+ issuer = try (each. value . issuer , null )
201+ }
202+ }
203+ }
204+
178205# VPC Link (Private API)
179206resource "aws_apigatewayv2_vpc_link" "this" {
180207 for_each = var. create && var. create_vpc_link ? var. vpc_links : {}
181208
182- name = lookup (each. value , " name" , each. key )
209+ name = try (each. value . name , each. key )
183210 security_group_ids = each. value [" security_group_ids" ]
184211 subnet_ids = each. value [" subnet_ids" ]
185212
186- tags = merge (var. tags , var. vpc_link_tags , lookup (each. value , " tags" , {}))
213+ tags = merge (var. tags , var. vpc_link_tags , try (each. value . tags , {}))
187214}
0 commit comments