簡體   English   中英

Terraform AWS LB 銷毀 Tears Down ASG

[英]Terraform AWS LB Destroy Tears Down ASG

目前 Terraform v1.1.7 用於創建 AWS ASG 和 LB。

LB TG 通過以下外部附件資源連接到 ASG:

resource "aws_autoscaling_attachment" "gateway_lb_attachment" {
  for_each = toset(local.asg_names)
  autoscaling_group_name = each.value
  lb_target_group_arn   = aws_lb_target_group.gateway_tg.arn
}

在 ASG 資源中存在以下生命周期規則:

  lifecycle {
    create_before_destroy = true
    ignore_changes = [ load_balancers, target_group_arns ]
  }

在啟動模板內有:

  lifecycle {
    create_before_destroy = true
  }

當 LB 被銷毀時,它會觸發 ASG 銷毀。 根據上面的配置,我的理解是 ASG 應該保持在原位。

有什么遺漏嗎?

在玩了各種配置后,我找到了一個贏家。

在模塊中將 ASG 名稱編譯為本地 EG 時失敗的早期版本

locals {

    asg_names = compact([for i in tolist([
      var.remote_state_lookup.outputs.asg_app_group_name,
      var.remote_state_lookup.outputs.asg_cicd_group_name,
      var.remote_state_lookup.outputs.asg_es_group_name
    ]) : i == "null" ? "" : i])
}

通過將其移動到模塊的實例化器並使用模塊輸出而不是遠程 state 數據源,解決了這個問題!

例如

在負載均衡器模塊中,將本地更改為 var:

variable "asg_names" {
  type    = list(string)
  default = null
}

現在在模塊實例化器中設置它的值:

  asg_names = compact([for i in tolist([
    try(module.eks_app_nodes[0].asg_group_name, "null"),
    try(module.eks_cicd_nodes[0].asg_group_name, "null"),
    try(module.eks_es_nodes[0].asg_group_name, "null")
  ]) : i == "null" ? "" : i])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM