代码示例:
下面是AWS ALB和API实例资源的例子:
resource "aws_alb" "example" { name = "example-alb" internal = false load_balancer_type = "application" subnets = [aws_subnet.example1.id, aws_subnet.example2.id]
access_logs { bucket = aws_s3_bucket.logs.bucket }
tags = { Environment = "production" } }
resource "aws_alb_target_group" "example" { name_prefix = "example-tg" port = 80 protocol = "HTTP" vpc_id = aws_vpc.example.id
health_check { healthy_threshold = 3 interval = 30 path = "/health" port = 80 protocol = "HTTP" timeout = 5 unhealthy_threshold = 3 }
tags = { Environment = "production" } }
resource "aws_alb_listener" "example" { load_balancer_arn = aws_alb.example.arn port = 80 protocol = "HTTP"
default_action { target_group