Skip to content

Commit 36a8734

Browse files
authored
Merge pull request #1 from HarriLLC/harri-changes
[HARRI-200501] Harri Changes
2 parents dd6826c + f39fd20 commit 36a8734

File tree

3 files changed

+78
-20
lines changed

3 files changed

+78
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ terraform.rc
3030

3131
# Zip archive
3232
*.zip
33+
34+
# pycharm
35+
.idea

main.tf

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ resource "aws_apigatewayv2_stage" "default" {
6666
api_id = aws_apigatewayv2_api.this[0].id
6767
name = "$default"
6868
auto_deploy = true
69-
69+
description = var.default_stage_description
7070
dynamic "access_log_settings" {
7171
for_each = var.default_stage_access_log_destination_arn != null && var.default_stage_access_log_format != null ? [true] : []
7272

@@ -111,6 +111,8 @@ resource "aws_apigatewayv2_stage" "default" {
111111
}
112112
}
113113

114+
### Api mappings
115+
114116
# Default API mapping
115117
resource "aws_apigatewayv2_api_mapping" "this" {
116118
count = var.create && var.create_api_domain_name && var.create_default_stage && var.create_default_stage_api_mapping ? 1 : 0
@@ -120,9 +122,20 @@ resource "aws_apigatewayv2_api_mapping" "this" {
120122
stage = aws_apigatewayv2_stage.default[0].id
121123
}
122124

125+
# Additional Api mappings
126+
resource "aws_apigatewayv2_api_mapping" "this_additional" {
127+
for_each = var.additional_default_stage_api_mappings
128+
129+
api_id = aws_apigatewayv2_api.this[0].id
130+
domain_name = each.value["domain_name"]
131+
stage = aws_apigatewayv2_stage.default[0].id
132+
api_mapping_key = each.value["api_mapping_key"]
133+
}
134+
135+
123136
# Routes and integrations
124137
resource "aws_apigatewayv2_route" "this" {
125-
for_each = var.create && var.create_routes_and_integrations ? var.integrations : {}
138+
for_each = var.create && var.create_routes_and_integrations ? var.routes : {}
126139

127140
api_id = aws_apigatewayv2_api.this[0].id
128141
route_key = each.key
@@ -134,7 +147,7 @@ resource "aws_apigatewayv2_route" "this" {
134147
model_selection_expression = try(each.value.model_selection_expression, null)
135148
operation_name = try(each.value.operation_name, null)
136149
route_response_selection_expression = try(each.value.route_response_selection_expression, null)
137-
target = "integrations/${aws_apigatewayv2_integration.this[each.key].id}"
150+
target = "integrations/${aws_apigatewayv2_integration.this[coalesce(each.value.integration_key, each.key)].id}"
138151

139152
# Have been added to the docs. But is WEBSOCKET only(not yet supported)
140153
# request_models = try(each.value.request_models, null)
@@ -144,37 +157,37 @@ resource "aws_apigatewayv2_integration" "this" {
144157
for_each = var.create && var.create_routes_and_integrations ? var.integrations : {}
145158

146159
api_id = aws_apigatewayv2_api.this[0].id
147-
description = try(each.value.description, null)
160+
description = each.value.description
148161

149-
integration_type = try(each.value.integration_type, try(each.value.lambda_arn, "") != "" ? "AWS_PROXY" : "MOCK")
150-
integration_subtype = try(each.value.integration_subtype, null)
151-
integration_method = try(each.value.integration_method, try(each.value.integration_subtype, null) == null ? "POST" : null)
152-
integration_uri = try(each.value.lambda_arn, try(each.value.integration_uri, null))
162+
integration_type = each.value.integration_type
163+
integration_subtype = each.value.integration_subtype
164+
integration_method = each.value.integration_method
165+
integration_uri = coalesce(each.value.lambda_arn, each.value.integration_uri)
153166

154-
connection_type = try(each.value.connection_type, "INTERNET")
167+
connection_type = each.value.connection_type
155168
connection_id = try(aws_apigatewayv2_vpc_link.this[each.value["vpc_link"]].id, try(each.value.connection_id, null))
156169

157-
payload_format_version = try(each.value.payload_format_version, null)
158-
timeout_milliseconds = try(each.value.timeout_milliseconds, null)
159-
passthrough_behavior = try(each.value.passthrough_behavior, null)
160-
content_handling_strategy = try(each.value.content_handling_strategy, null)
161-
credentials_arn = try(each.value.credentials_arn, null)
170+
payload_format_version = each.value.payload_format_version
171+
timeout_milliseconds = each.value.timeout_milliseconds
172+
passthrough_behavior = each.value.passthrough_behavior
173+
content_handling_strategy = each.value.content_handling_strategy
174+
credentials_arn = each.value.credentials_arn
162175
request_parameters = try(jsondecode(each.value["request_parameters"]), each.value["request_parameters"], null)
163176

164177
dynamic "tls_config" {
165-
for_each = flatten([try(jsondecode(each.value["tls_config"]), each.value["tls_config"], [])])
178+
for_each = each.value["tls_config"] ? [1] : []
166179

167180
content {
168-
server_name_to_verify = tls_config.value["server_name_to_verify"]
181+
server_name_to_verify = each.value["tls_config_server_name_to_verify"]
169182
}
170183
}
171184

172185
dynamic "response_parameters" {
173-
for_each = flatten([try(jsondecode(each.value["response_parameters"]), each.value["response_parameters"], [])])
186+
for_each = each.value["response_parameters"] ? [1] : []
174187

175188
content {
176-
status_code = response_parameters.value["status_code"]
177-
mappings = response_parameters.value["mappings"]
189+
status_code = each.value["response_parameters_status_code"]
190+
mappings = each.value["response_parameters_mappings"]
178191
}
179192
}
180193

variables.tf

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ variable "create_default_stage_api_mapping" {
2222
default = true
2323
}
2424

25+
variable "additional_default_stage_api_mappings" {
26+
description = "additional mapping for default stage"
27+
type = map(object({
28+
domain_name = string
29+
api_mapping_key = string
30+
}))
31+
default = {}
32+
}
33+
34+
35+
variable "default_stage_description" {
36+
description = "default stage description"
37+
type = string
38+
default = ""
39+
}
40+
41+
variable "routes" {
42+
description = "apigateway routes to create"
43+
type = map(any)
44+
default = {}
45+
}
46+
2547
# variable "create_stage" {
2648
# description = "Whether to create custom stage"
2749
# type = bool
@@ -196,7 +218,27 @@ variable "mutual_tls_authentication" {
196218
# routes and integrations
197219
variable "integrations" {
198220
description = "Map of API gateway routes with integrations"
199-
type = map(any)
221+
type = map(object({
222+
description = optional(string, null)
223+
integration_type = optional(string, "HTTP_PROXY")
224+
integration_subtype = optional(string, null)
225+
integration_method = optional(string, null)
226+
integration_uri = optional(string, null)
227+
lambda_arn = optional(string, null)
228+
connection_type = optional(string, "INTERNET")
229+
connection_id = optional(string, null)
230+
payload_format_version = optional(string, null)
231+
timeout_milliseconds = optional(string, null)
232+
passthrough_behavior = optional(string, null)
233+
content_handling_strategy = optional(string, null)
234+
credentials_arn = optional(string, null)
235+
request_parameters = optional(map(string), {})
236+
tls_config = optional(bool, false)
237+
tls_config_server_name_to_verify = optional(string, null)
238+
response_parameters = optional(bool, false)
239+
response_parameters_status_code = optional(number,null)
240+
response_parameters_mappings = optional(map(string), {})
241+
}))
200242
default = {}
201243
}
202244

0 commit comments

Comments
 (0)