-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
69 lines (54 loc) · 1.57 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
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0.0"
}
}
}
resource "aws_api_gateway_rest_api" "this" {
name = "${var.application_name}"
body = var.schema
}
resource "aws_api_gateway_deployment" "this" {
rest_api_id = aws_api_gateway_rest_api.this.id
triggers = {
redeployment = sha256(var.schema)
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_api_gateway_base_path_mapping" "this" {
api_id = aws_api_gateway_rest_api.this.id
stage_name = aws_api_gateway_stage.this.stage_name
domain_name = var.domain_name
base_path = var.base_path
}
resource "aws_api_gateway_stage" "this" {
rest_api_id = aws_api_gateway_rest_api.this.id
deployment_id = aws_api_gateway_deployment.this.id
stage_name = var.stage_name
xray_tracing_enabled = var.enable_xray
access_log_settings {
destination_arn = aws_cloudwatch_log_group.api_gateway_access_log.arn
format = file("${path.module}/resources/access_log_format.json")
}
variables = {
hash = sha256(var.schema)
}
}
resource "aws_cloudwatch_log_group" "api_gateway_access_log" {
name = "API-Gateway-${aws_api_gateway_rest_api.this.name}-access-log"
retention_in_days = var.access_log_retention_in_days
}
resource "aws_api_gateway_method_settings" "this" {
count = var.enable_metrics ? 1 : 0
rest_api_id = aws_api_gateway_rest_api.this.id
stage_name = aws_api_gateway_stage.this.stage_name
method_path = "*/*"
settings {
metrics_enabled = true
}
}