-
Notifications
You must be signed in to change notification settings - Fork 3
/
kcp_http_proxy.tf
132 lines (114 loc) · 3.28 KB
/
kcp_http_proxy.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
variable "dynamodb_table_name_kcp_payment_approval_requests" {
default = "kcp-payment-approval-requests"
}
# ECS
resource "aws_ecr_repository" "kcp_http_proxy" {
name = "ridi/kcp-http-proxy"
count = module.global_variables.is_prod ? 1 : 0
}
resource "aws_ecs_cluster" "kcp_http_proxy" {
name = "kcp-http-proxy-${module.global_variables.env}"
setting {
name = "containerInsights"
value = module.global_variables.is_prod ? "enabled" : "disabled"
}
}
resource "aws_lb" "kcp_http_proxy" {
name = "kcp-http-proxy-${module.global_variables.env}"
internal = true
load_balancer_type = "application"
security_groups = [aws_security_group.kcp_http_proxy.id]
subnets = [
aws_subnet.private_2a.id,
aws_subnet.private_2c.id,
]
enable_deletion_protection = true
tags = {
Environment = module.global_variables.env
}
}
resource "aws_lb_target_group" "kcp_http_proxy" {
port = 80
protocol = "HTTP"
target_type = "ip"
vpc_id = aws_vpc.vpc.id
deregistration_delay = 60
depends_on = [aws_lb.kcp_http_proxy]
health_check {
path = "/health"
matcher = "200"
}
}
resource "aws_lb_listener" "kcp_http_proxy" {
load_balancer_arn = aws_lb.kcp_http_proxy.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.kcp_http_proxy.arn
}
}
# CloudWatch
resource "aws_cloudwatch_log_group" "kcp_http_proxy_logs" {
name = "${module.global_variables.env}.kcp-http-proxy"
tags = {
Environment = module.global_variables.env
}
}
# Security Groups
resource "aws_security_group" "kcp_http_proxy" {
vpc_id = aws_vpc.vpc.id
name = "kcp-http-proxy"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = [
aws_vpc.vpc.cidr_block
]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "kcp-http-proxy-${module.global_variables.env}"
}
}
resource "aws_dynamodb_table" "kcp_payment_approval_requests" {
name = "${var.dynamodb_table_name_kcp_payment_approval_requests}-${module.global_variables.env}"
billing_mode = "PAY_PER_REQUEST"
hash_key = "id"
attribute {
name = "id"
type = "S"
}
ttl {
attribute_name = "ttl"
enabled = true
}
tags = {
Name = var.dynamodb_table_name_kcp_payment_approval_requests
Environment = module.global_variables.env
}
}
resource "aws_cloudwatch_metric_alarm" "kcp_http_proxy_unhealthy_host_count" {
count = module.global_variables.is_prod ? 1 : 0
alarm_name = "kcp-http-proxy-unhealthy-host-count"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "1"
metric_name = "UnHealthyHostCount"
namespace = "AWS/ApplicationELB"
period = "300"
statistic = "Maximum"
threshold = "1"
alarm_actions = [data.aws_sns_topic.cloudwatch_alarm.arn]
alarm_description = "ECS Task 1개 이상 Unhealthy"
datapoints_to_alarm = 1
dimensions = {
LoadBalancer = aws_lb.kcp_http_proxy.arn_suffix
TargetGroup = aws_lb_target_group.kcp_http_proxy.arn_suffix
}
}