Terraform:EKS 模块的动态嵌套组
我正在尝试使用 Terraform AWS EKS 模块在不同环境中配置 EKS (https ://registry.terraform.io/modules/terraform-aws-modules/eks/)。环境因 EKS 托管节点组的数量而异。我使用对象列表来描述变量中的节点组:
node_groups = [
{
"name" = "nodegroup_name"
"desired_capacity" = 1,
"max_capacity" = 3,
"min_capacity" = 1,
"subnets" = "internal",
"instance_types" = "r5.xlarge",
"k8s_labels" = {
NodeGroup = "internal"
}
}
]
这是节点组定义的模块代码:
for_each = { for node_group in var.node_groups : node_group.name => node_group }
eks_managed_node_groups = {
nodegroup={
name = each.key
desired_capacity = each.value.desired_capacity
max_capacity = each.value.max_capacity
min_capacity = each.value.min_capacity
subnets = each.value.subnets != "external" ? data.aws_subnets.eks_external_subnets.ids : data.aws_subnets.eks_internal_subnets.ids
instance_types = [each.value.instance_types]
source_security_group_ids = each.value.subnets != "external" ? [ aws_security_group.eks-external-sec-group.id ] : [ aws_security_group.eks-internal-sec-group.id ]
capacity_type = "ON_DEMAND"
k8s_labels = each.value.k8s_labels
additional_tags = local.tags
}
}
但是 terraform plan 返回错误:
Error: Incorrect attribute value type
on ../../../modules/aws/eks/main.tf line 66, in data "aws_eks_cluster_auth" "this":
66: name = module.eks_remote.cluster_id
Inappropriate value for attribute "name": string required.
Error: Invalid function argument
on ../../../modules/aws/eks/main.tf line 101, in locals:
101: ${chomp(module.eks_remote.aws_auth_configmap_yaml)}
Invalid value for "str" parameter: string required.
在日志中我看到很多以下消息: [WARN] ReferenceTransformer:找不到引用:“each.value”
有人可以帮我解决这个问题吗?
I'm trying to configure EKS on different environments with Terraform AWS EKS module (https://registry.terraform.io/modules/terraform-aws-modules/eks/). Environments differ by number of EKS-managed node groups. I'm using list of objects to describe nodegroups in a varibale:
node_groups = [
{
"name" = "nodegroup_name"
"desired_capacity" = 1,
"max_capacity" = 3,
"min_capacity" = 1,
"subnets" = "internal",
"instance_types" = "r5.xlarge",
"k8s_labels" = {
NodeGroup = "internal"
}
}
]
And here's the module code for node groups definition:
for_each = { for node_group in var.node_groups : node_group.name => node_group }
eks_managed_node_groups = {
nodegroup={
name = each.key
desired_capacity = each.value.desired_capacity
max_capacity = each.value.max_capacity
min_capacity = each.value.min_capacity
subnets = each.value.subnets != "external" ? data.aws_subnets.eks_external_subnets.ids : data.aws_subnets.eks_internal_subnets.ids
instance_types = [each.value.instance_types]
source_security_group_ids = each.value.subnets != "external" ? [ aws_security_group.eks-external-sec-group.id ] : [ aws_security_group.eks-internal-sec-group.id ]
capacity_type = "ON_DEMAND"
k8s_labels = each.value.k8s_labels
additional_tags = local.tags
}
}
But terraform plan returns errors:
Error: Incorrect attribute value type
on ../../../modules/aws/eks/main.tf line 66, in data "aws_eks_cluster_auth" "this":
66: name = module.eks_remote.cluster_id
Inappropriate value for attribute "name": string required.
Error: Invalid function argument
on ../../../modules/aws/eks/main.tf line 101, in locals:
101: ${chomp(module.eks_remote.aws_auth_configmap_yaml)}
Invalid value for "str" parameter: string required.
And in logs I see a lot of the following messages:[WARN] ReferenceTransformer: reference not found: "each.value"
Can somebody, please, help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据OP的评论,我能够创建一个动态
eks_management_node_groups
对象。完整的解决方案如下所示:您可以使用其他 terrafrom 函数来创建可选值的默认值和后备值。生成托管节点对象后,您可以通过设置
eks_management_node_groups = local.eks_nodegroups
将其传递给 eks 模块Based on OP's comment I was able to create a dynamic
eks_managed_node_groups
object. The complete solution would look something like this:You can use additional terrafrom functions to create defaults and fallbacks for optional values. Once your managed nodes object is generated you can just pass it to the eks module by setting
eks_managed_node_groups = local.eks_nodegroups