
關於當我嘗試將第二個目標群組新增至自動縮放群組時遇到的 Terraform 錯誤的問題。
我成功建立了一個名為「ext_alb_targetgroup」的新目標群組。它顯示在 AWS 控制台中,並且 ALB 偵聽器正在轉送給它。我想將這個新目標群組加入現有 ASG 中,作為 ASG 的第二個目標群組。根據 Terraform 文檔,ASG 可以是多個目標群組的成員,並且可以向參數「target_group_arns」傳遞 TG 列表。所以我將我的新 TG 添加到了 ASG 的清單中。我正在配置的 ASG 位於一個模組中,而我嘗試添加到此 ASG 配置中的新 TG 位於另一個模組中。當我運行 terraform 計劃時,它會拋出以下錯誤:
Error: resource 'aws_autoscaling_group.asg' config: unknown resource 'aws_alb_target_group.ext_alb_targetgroup' referenced in variable aws_alb_target_group.ext_alb_targetgroup.arn
我運行了“terraform show”,它發現 TG 資源很好,就像我說的 TG 資源是 AWS。
有人知道為什麼 terraform 會拋出這個錯誤?我沒有正確調用資源嗎?這是我在 ASG 配置中的 target_group_arns 列表:
target_group_arns = [ "${aws_alb_target_group.alb_targetgroup443.arn}",
"${aws_alb_target_group.ext_alb_targetgroup.arn}"
]
第二個 TG 是 TF 引發錯誤的那個。
答案1
我認為您正在使用資源已更改的版本
resource/aws_alb_* & data-source/aws_alb_*: In order to support network LBs, ALBs were renamed to aws_lb_* due to the way APIs "new" (non-Classic) load balancers are structured in AWS. All existing ALB functionality remains untouched and new resources work the same way. aws_alb_* resources are still in place as "aliases", but documentation will only mention aws_lb_*. aws_alb_* aliases will be removed in future major version. (#1806)
Deprecated:
data-source/aws_alb
data-source/aws_alb_listener
data-source/aws_alb_target_group
resource/aws_alb
resource/aws_alb_listener
resource/aws_alb_listener_rule
resource/aws_alb_target_group
resource/aws_alb_target_group_attachment