我有一个目标组,想通过 terraform 将 alb 注册为目标组的目标。https://aws.amazon.com/blogs/networking-and-content-delivery/application-load-balancer-type-target-group-for-network-load-balancer/ https://aws.amazon.com/blogs/networking-and-content-delivery/application-load-balancer-type-target-group-for-network-load-balancer/我有点找不到与此相关的文档。有人可以帮忙吗?
Terraform 文档尚未完全更新以反映新的 ALB 作为 NLB 功能的目标组。尽管如此,您应该能够通过查看 AWS API 参考和 terraform 文档来执行与下面的代码片段类似的操作:
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
}
# Create ALB
resource "aws_lb" "alb" {
name = "test-alb-tf"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.lb_sg.id]
subnets = aws_subnet.public.*.id
}
# Create ALB target group
resource "aws_lb_target_group" "alb_tg" {
name = "tf-example-lb-tg"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.main.id
}
# Create NLB
resource "aws_lb" "nlb" {
name = "test-nlb-tf"
internal = false
load_balancer_type = "network"
subnets = aws_subnet.public.*.id
}
# Create NLB target group that forwards traffic to alb
# https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateTargetGroup.html
resource "aws_lb_target_group" "nlb_tg" {
name = "tf-example-nlb-tg"
port = 80
protocol = "TCP"
vpc_id = aws_vpc.main.id
target_type = "alb"
}
# Create target group attachment
# More details: https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_TargetDescription.html
# https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_RegisterTargets.html
resource "aws_lb_target_group_attachment" "tg_attachment" {
target_group_arn = aws_lb_target_group.nlb_tg.arn
# attach the ALB to this target group
target_id = aws_lb.alb.arn
# If the target type is alb, the targeted Application Load Balancer must have at least one listener whose port matches the target group port.
port = 80
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)