-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
79 lines (70 loc) · 2.19 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
terraform {
required_version = ">= 1.4.0"
}
locals {
domain_name = var.full_domain_name
}
resource "aws_apigatewayv2_api" "proxy" {
name = var.api_display_name
description = var.api_description
protocol_type = "HTTP"
disable_execute_api_endpoint = true
}
resource "aws_apigatewayv2_stage" "proxy" {
api_id = aws_apigatewayv2_api.proxy.id
name = "default"
deployment_id = aws_apigatewayv2_deployment.proxy.id
access_log_settings {
destination_arn = aws_cloudwatch_log_group.proxy.arn
format = join(" ", [
"$context.identity.sourceIp",
"$context.identity.caller",
"$context.identity.user",
"[$context.requestTime]",
"$context.httpMethod",
"$context.resourcePath",
"$context.protocol",
"$context.status",
"$context.responseLength",
"$context.requestId",
"$context.extendedRequestId"
])
}
default_route_settings {
detailed_metrics_enabled = true
throttling_rate_limit = 1000
throttling_burst_limit = 1000
}
}
resource "aws_apigatewayv2_api_mapping" "proxy" {
api_id = aws_apigatewayv2_api.proxy.id
domain_name = aws_apigatewayv2_domain_name.proxy.domain_name
stage = aws_apigatewayv2_stage.proxy.id
api_mapping_key = var.api_mapping_key
}
resource "aws_apigatewayv2_deployment" "proxy" {
api_id = aws_apigatewayv2_api.proxy.id
triggers = {
redeployment = sha1(join(",", tolist([
jsonencode(aws_apigatewayv2_api.proxy),
jsonencode(aws_apigatewayv2_integration.proxy),
jsonencode(aws_apigatewayv2_route.proxy),
])))
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_apigatewayv2_route" "proxy" {
count = var.auto_create_route ? 1 : 0
api_id = aws_apigatewayv2_api.proxy.id
route_key = "$default"
target = format("integrations/%s", var.auto_create_route ? aws_apigatewayv2_integration.proxy[0].id : "")
}
resource "aws_apigatewayv2_integration" "proxy" {
count = var.auto_create_route ? 1 : 0
api_id = aws_apigatewayv2_api.proxy.id
integration_type = "HTTP_PROXY"
integration_method = "ANY"
integration_uri = var.target_url
}