1

我使用terraform-aws-eks 模块创建了一个 AWS EKS 集群。Terraform 版本是 1.0.6,aws 提供者版本是 3.60.0。有了这些版本,我应该能够使用aws_autoscaling_group_tag资源来标记由 EKS 创建的 ASG。

我的问题是模块中的节点组是地图的映射(在此处描述),我不知道如何遍历我的节点组以标记其中的所有 ASG。以下是 terraform 的示例:

resource "aws_eks_node_group" "example" {
  cluster_name    = "example"
  node_group_name = "example"

  # ... other configuration ...
}

resource "aws_autoscaling_group_tag" "example" {
  for_each = toset(
    [for asg in flatten(
      [for resources in aws_eks_node_group.example.resources : resources.autoscaling_groups]
    ) : asg.name]
  )

  autoscaling_group_name = each.value

  tag {
    key   = "k8s.io/cluster-autoscaler/node-template/label/eks.amazonaws.com/capacityType"
    value = "SPOT"

    propagate_at_launch = false
  }
}

在这种情况下,有一个特定的节点组。但就我而言,有 3 个节点组,我希望标记所有 ASG。到目前为止,我还没有在 terraform 中使用太多循环,我什至不确定它是否会起作用。我很感激任何帮助!

4

0 回答 0