我有一个VPC模块,它有以下输出。
$ tf output
dev_cp_subnet_ids = [
tolist([
"subnet-0cb8b0a98205082d8",
"subnet-03964e7892b6a5336",
"subnet-0917a9e6d87918c87",
]),
]
vpc_id = "vpc-06f3520baa1199f6b"我想在另一个模块,即土拨鼠中使用上面的值
我首先声明远程状态配置。
data "terraform_remote_state" "vpc" {
backend = "http"
config = {
address = "..."
}
}然后作为模块调用的一部分,执行以下操作
module "eks" {
source = "terraform-aws-modules/eks/aws"
cluster_name = "build"
cluster_version = "1.22"
cluster_endpoint_private_access = true
cluster_endpoint_public_access = true
cluster_addons = {
coredns = {}
kube-proxy = {}
vpc-cni = {}
}
vpc_id = data.terraform_remote_state.vpc.outputs.vpc_id
subnet_ids = data.terraform_remote_state.vpc.outputs.dev_cp_subnet_ids正如我在一个vpc_id中看到的那样,tf plan成功地获取了它
}
+ vpc_id = "vpc-06f3520baa1199f6b"
}
Plan: 41 to add, 0 to change, 0 to destroy.但是对于dev_cp_subnet_ids,我得到以下错误
│ Error: Invalid value for module argument
│
│ on main.tf line 24, in module "eks":
│ 24: subnet_ids = data.terraform_remote_state.vpc.outputs.dev_cp_subnet_ids
│
│ The given value is not suitable for child module variable "subnet_ids"
│ defined at .terraform/modules/eks/variables.tf:53,1-22: incorrect list
│ element type: string required.根据文档 for subnet_ids,其类型为list(string)。我的理解是,下面的输出是列表(String)的格式
dev_cp_subnet_ids = [
tolist([
"subnet-0cb8b0a98205082d8",
"subnet-03964e7892b6a5336",
"subnet-0917a9e6d87918c87",
]),
]还是我在这里漏掉了什么?
发布于 2022-07-19 18:52:28
您在问题末尾显示的表达式如下:
tuple([list(string)])也就是说:一个单元素元组,其元素本身就是一个字符串列表。
由于Terraform知道subnet_ids需要一个字符串列表,所以它首先尝试将其自动转换为列表类型,并因此生成以下类型的值:
list(list(string))Terraform随后注意到,这个结果列表的元素类型是list(string),而不是参数所要求的string,因此返回此错误。
您可以通过删除外部括号[ .. ]来解决这个问题,这样您就可以直接分配tolist结果,这将是一个字符串列表,如预期的那样:
dev_cp_subnet_ids = tolist([
"subnet-0cb8b0a98205082d8",
"subnet-03964e7892b6a5336",
"subnet-0917a9e6d87918c87",
]),https://stackoverflow.com/questions/73040624
复制相似问题