56 lines
1.3 KiB
HCL
56 lines
1.3 KiB
HCL
#로드밸런서
|
|
resource "aws_lb" "alb" {
|
|
name = "${var.name}-alb"
|
|
load_balancer_type = "application"
|
|
subnets = var.subnet_ids
|
|
security_groups = var.sg_ids
|
|
}
|
|
# ALB LISTENER
|
|
resource "aws_lb_listener" "http" {
|
|
load_balancer_arn = aws_lb.alb.arn
|
|
port = "80"
|
|
protocol = "HTTP"
|
|
|
|
default_action {
|
|
type = "forward"
|
|
target_group_arn = aws_lb_target_group.instance.arn
|
|
}
|
|
}
|
|
# ALB Listener rule
|
|
resource "aws_lb_listener_rule" "alb-lsn-rule" {
|
|
listener_arn = aws_lb_listener.http.arn
|
|
priority = 100
|
|
|
|
condition {
|
|
path_pattern {
|
|
values = ["*"]
|
|
}
|
|
# field = "path-pattern"
|
|
# values = ["*"]
|
|
}
|
|
|
|
action {
|
|
type = "forward"
|
|
target_group_arn = aws_lb_target_group.instance.arn
|
|
}
|
|
depends_on = [
|
|
aws_lb_listener.http
|
|
]
|
|
}
|
|
|
|
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group
|
|
# ALB TARGET GROUP
|
|
resource "aws_lb_target_group" "instance" {
|
|
name = "web-tg"
|
|
port = 80
|
|
protocol = "HTTP"
|
|
vpc_id = var.vpc_id
|
|
}
|
|
|
|
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group_attachment
|
|
resource "aws_lb_target_group_attachment" "instance" {
|
|
target_group_arn = aws_lb_target_group.instance.arn
|
|
target_id = var.instance_id
|
|
port = 80
|
|
}
|