首页 > 解决方案 > 自从我更新 Terraform 模块后出现错误

问题描述

我更新了 Terraform 版本和 eks 模块。现在我在运行 terraform 脚本(之前运行良好)时遇到了很多错误。其中一些是我修复的。

    Error: Invalid value for module argument

  on eks.tf line 27, in module "eks":
  27:   map_roles = [
  28:      {
  29:       role_arn = "${format("arn:aws:iam::%s:role/admin", var.target_account_id)}"
  30:       username = "${format("%s-admin", var.name)}"
  31:       group    = ["system:masters"]
  32:      },
  33:    ]

The given value is not suitable for child module variable "map_roles" defined
at
.terraform/modules/eks/terraform-aws-modules-terraform-aws-eks-1be1a02/variables.tf:63,1-21:
element 0: attributes "groups" and "rolearn" are required.


Error: Unsupported block type

  on provider.tf line 30, in data "terraform_remote_state" "state":
  30:   config {

Blocks of type "config" are not expected here. Did you mean to define argument
"config"? If so, use the equals sign to assign it a value.

我相信他们已经删除了map_accounts_count 和 map_roles_count变量。

文档不是那么清楚。我什至检查了发行说明。

下面是我的 eks.tf

module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "6.0.2"

  cluster_name = "${var.name}"
  subnets      = ["${module.vpc.private_subnets}"]
  vpc_id       = "${module.vpc.vpc_id}"
  cluster_version = "${var.cluster_version}"

  kubeconfig_aws_authenticator_additional_args = ["-r", "arn:aws:iam::${var.target_account_id}:role/terraform"]

  worker_groups = [
    {
      instance_type        = "${var.eks_instance_type}"
      asg_desired_capacity = "${var.eks_asg_desired_capacity}"
      asg_max_size         = "${var.eks_asg_max_size}"
      key_name             = "${var.key_name}"
    },
  ]


  map_accounts = ["${var.target_account_id}"]
  map_roles = [
     {
      role_arn = "${format("arn:aws:iam::%s:role/admin", var.target_account_id)}"
      username = "${format("%s-admin", var.name)}"
      group    = ["system:masters"]
     },
   ]


  #map_accounts_count = "1"
  #map_roles_count    = "1"

  write_kubeconfig      = "false"
  write_aws_auth_config = "false"
}

resource "local_file" "kubeconfig" {
  content  = "${module.eks.kubeconfig}"
  filename = "./.kube_config.yaml"
}

标签: terraformterraform-provider-aws

解决方案


基于https://github.com/terraform-aws-modules/terraform-aws-eks/blob/v6.0.2/variables.tf#L63-L71和您需要更新的错误:

  • groupgroups
  • role_arnrolearn

除此之外,您需要更新地图以使用https://www.terraform.io/docs/providers/terraform/d/remote_state.html=上的文档建议的分配。您的远程状态配置(可能还有其他地图)需要如下所示:

map = {
  data = "string"
}

代替

map {
  data = "string"
}

推荐阅读