@@ -22,12 +22,12 @@ resource "aws_apigatewayv2_api" "this" {
22
22
for_each = length (keys (var. cors_configuration )) == 0 ? [] : [var . cors_configuration ]
23
23
24
24
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 )
31
31
}
32
32
}
33
33
@@ -48,9 +48,10 @@ resource "aws_apigatewayv2_domain_name" "this" {
48
48
49
49
dynamic "mutual_tls_authentication" {
50
50
for_each = length (keys (var. mutual_tls_authentication )) == 0 ? [] : [var . mutual_tls_authentication ]
51
+
51
52
content {
52
53
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 )
54
55
}
55
56
}
56
57
@@ -67,6 +68,7 @@ resource "aws_apigatewayv2_stage" "default" {
67
68
68
69
dynamic "access_log_settings" {
69
70
for_each = var. default_stage_access_log_destination_arn != null && var. default_stage_access_log_format != null ? [true ] : []
71
+
70
72
content {
71
73
destination_arn = var. default_stage_access_log_destination_arn
72
74
format = var. default_stage_access_log_format
@@ -75,12 +77,13 @@ resource "aws_apigatewayv2_stage" "default" {
75
77
76
78
dynamic "default_route_settings" {
77
79
for_each = length (keys (var. default_route_settings )) == 0 ? [] : [var . default_route_settings ]
80
+
78
81
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 )
84
87
}
85
88
}
86
89
@@ -89,11 +92,11 @@ resource "aws_apigatewayv2_stage" "default" {
89
92
# for_each = var.create_routes_and_integrations ? var.integrations : {}
90
93
# content {
91
94
# 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)
97
100
# }
98
101
# }
99
102
@@ -121,49 +124,51 @@ resource "aws_apigatewayv2_route" "this" {
121
124
api_id = aws_apigatewayv2_api. this [0 ]. id
122
125
route_key = each. key
123
126
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 )
130
133
target = " integrations/${ aws_apigatewayv2_integration . this [each . key ]. id } "
131
134
132
135
# 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)
135
138
}
136
139
137
140
resource "aws_apigatewayv2_integration" "this" {
138
141
for_each = var. create && var. create_routes_and_integrations ? var. integrations : {}
139
142
140
143
api_id = aws_apigatewayv2_api. this [0 ]. id
141
- description = lookup (each. value , " description" , null )
144
+ description = try (each. value . description , null )
142
145
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 ))
147
150
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 ))
150
153
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 )
156
159
request_parameters = try (jsondecode (each. value [" request_parameters" ]), each. value [" request_parameters" ], null )
157
160
158
161
dynamic "tls_config" {
159
162
for_each = flatten ([try (jsondecode (each. value [" tls_config" ]), each. value [" tls_config" ], [])])
163
+
160
164
content {
161
165
server_name_to_verify = tls_config. value [" server_name_to_verify" ]
162
166
}
163
167
}
164
168
165
169
dynamic "response_parameters" {
166
170
for_each = flatten ([try (jsondecode (each. value [" response_parameters" ]), each. value [" response_parameters" ], [])])
171
+
167
172
content {
168
173
status_code = response_parameters. value [" status_code" ]
169
174
mappings = response_parameters. value [" mappings" ]
@@ -175,13 +180,35 @@ resource "aws_apigatewayv2_integration" "this" {
175
180
}
176
181
}
177
182
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
+
178
205
# VPC Link (Private API)
179
206
resource "aws_apigatewayv2_vpc_link" "this" {
180
207
for_each = var. create && var. create_vpc_link ? var. vpc_links : {}
181
208
182
- name = lookup (each. value , " name" , each. key )
209
+ name = try (each. value . name , each. key )
183
210
security_group_ids = each. value [" security_group_ids" ]
184
211
subnet_ids = each. value [" subnet_ids" ]
185
212
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 , {}))
187
214
}
0 commit comments