【发布时间】:2018-12-05 18:23:28
【问题描述】:
我正在尝试使用 Terraform 在 AWS 上预置演示 Web 服务,但遇到以下错误。
Error: Error applying plan:
2 error(s) occurred:
* module.prod.module.web.module.web.aws_alb_listener.frontend: 1 error(s) occurred:
* aws_alb_listener.frontend: Error creating LB Listener: ValidationError: 'arn:aws:elasticloadbalancing:us-west-2:114416042199:loadbalancer/app/demo-svc-prod-alb/2a5f486a7b9d265a' is not a valid target group ARN
status code: 400, request id: e3819755-799c-11e8-ac82-43dfdd4e44d1
* module.prod.module.web.module.web.aws_autoscaling_group.backend: 1 error(s) occurred:
* aws_autoscaling_group.backend: Error creating AutoScaling Group: ValidationError: Provided Load Balancers may not be valid. Please ensure they exist and try again.
status code: 400, request id: e37efee9-799c-11e8-955a-c50a9e447dfa
我不明白为什么 ARN 无效,因为它属于 Terraform 创建的资源。 ARN 引用elasticloadbalancing 似乎很可疑。使用 AWS 应用程序负载均衡器和 ASG 时是否需要注意任何问题?使用经典 ELB 时,我没有看到这个问题。有什么方法可以从 Terraform 中获取更多有用的信息?
引发错误的相关资源是:
resource "aws_alb_listener" "frontend" {
load_balancer_arn = "${aws_alb.frontend.arn}"
port = "${local.https_port}"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
default_action {
target_group_arn = "${aws_alb.frontend.arn}"
type = "forward"
}
}
和
resource "aws_autoscaling_group" "backend" {
name = "${local.cluster_name}-asg"
launch_configuration = "${aws_launch_configuration.backend.id}"
availability_zones = ["${data.aws_availability_zones.all.names}"]
load_balancers = ["${aws_alb.frontend.name}"]
health_check_type = "ELB"
min_size = "${var.min_size}"
max_size = "${var.max_size}"
// This resource type uses different tags specification format.
// A list comp over the locals tags map would sure come in handy to keep
// things DRY.
tags = [
{
key = "System"
value = "${var.tags["System"]}"
propagate_at_launch = true
},
{
key = "Environment"
value = "${local.tags["Environment"]}"
propagate_at_launch = true
},
{
key = "Owner"
value = "${local.tags["Owner"]}"
propagate_at_launch = true
},
{
key = "Description"
value = "${local.tags["Description"]}"
propagate_at_launch = true
}
]
}
完整代码可在https://github.com/mojochao/terraform-aws-web-stack/commit/a4bfe5d6362fddfb2934dc9a89344c304e59cef7获取。
【问题讨论】:
标签: amazon-ec2 terraform