This repository was archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
87 lines (65 loc) · 1.95 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
80
81
82
83
84
85
86
87
locals {
apigateway_stage_name = "production"
apigateway_path = "/update"
}
resource "aws_api_gateway_rest_api" "this" {
name = var.name
endpoint_configuration {
types = ["REGIONAL"]
}
binary_media_types = ["*/*"]
body = jsonencode({
swagger = "2.0"
info = {
title = var.name
version = 1
}
schemes = ["https"]
paths = {
(local.apigateway_path) = {
get = {
responses = {}
x-amazon-apigateway-integration = {
uri = aws_lambda_function.this.invoke_arn
httpMethod = "POST"
type = "aws_proxy"
}
}
}
}
x-amazon-apigateway-binary-media-types = ["*/*"]
})
tags = var.tags
}
resource "aws_api_gateway_deployment" "this" {
rest_api_id = aws_api_gateway_rest_api.this.id
stage_name = "import_${md5(aws_api_gateway_rest_api.this.body)}"
lifecycle {
# The stage needs to use the new deployment first before dropping the old deployment
create_before_destroy = true
}
}
resource "aws_api_gateway_stage" "this" {
rest_api_id = aws_api_gateway_rest_api.this.id
stage_name = local.apigateway_stage_name
deployment_id = aws_api_gateway_deployment.this.id
tags = var.tags
depends_on = [aws_cloudwatch_log_group.apigateway]
}
resource "aws_api_gateway_method_settings" "this" {
rest_api_id = aws_api_gateway_rest_api.this.id
stage_name = aws_api_gateway_stage.this.stage_name
method_path = "*/*"
settings {
data_trace_enabled = true
logging_level = "INFO"
metrics_enabled = true
}
}
# Write permissions for CloudWatch Logs groups are granted via a service wide used IAM role
# https://eu-west-1.console.aws.amazon.com/apigateway/home?region=eu-west-1#/settings
resource "aws_cloudwatch_log_group" "apigateway" {
name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.this.id}/${local.apigateway_stage_name}"
retention_in_days = 3
tags = var.tags
}