我有一个glue job
在aws
。我做了一个循环。
在 variables.tf
variable "list_of_jobs" {
type = list(string)
default = ["myjob1","myjob2","myjob3"]
}
在 glue.tf
resource "aws_glue_job" "this" {
for_each = toset(var.list_of_jobs)
name = each.value
role_arn = var.role_arn
command {
name = "pythonshell"
python_version = 3
script_location = "s3://mybucket/${each.value}/run.py"
}
}
在 main.tf
variable "region" {}
variable "list_of_jobs" {}
module "my_glue" {
source = "../terraform-glue"
region = var.region
list_of_jobs = var.list_of_jobs
}
这个循环工作正常,glue jobs
执行之后我有3个terraform apply
。当我尝试制作问题时:
export TF_VAR_list_of_jobs='["myjob1","myjob2","myjob3"]'
在这种情况下,当我制作时terraform apply
,我会收到以下信息:
Error: Invalid function argument
on ../terraform-glue/glue.tf line 2, in resource "aws_glue_job" "this":
2: for_each = toset(var.list_of_jobs)
|----------------
| var.list_of_jobsis "[\"myjob1\",\"myjob2\",\"myjob3\"]"
Invalid value for "v" parameter: cannot convert string to set of any single
type.
输入变量,也不起作用。仅来自的变量variables.tf
。请问你能帮帮我吗 ?我整夜想解决这个问题。
它不起作用,因为如果要通过env变量传递它,则需要为复杂变量提供类型约束:
variable "list_of_jobs" {
type = list(string)
default = ["myjob1","myjob2","myjob3"]
}
variable "list_of_jobs" { type = list(string) }
我这样做了,但是结果list of string required
@Piduna因此,请提供字符串列表,这就是您的名字
list_of_jobs
。@Piduna您也可以从类型中删除字符串,
type = list
如果需要的话就可以使用。但是,对于复杂类型,必须存在类型,如清单所示。The given value is not suitable for child module variable "list_of_job" defined
在我的variables.tf中,variable "list_of_jobs" { type = list # default = ["myjob1","myjob2","myjob3"] }
在我的main.tf中,变量“ list_of_jobs” {}terraform apply -var='list_of_jobs=["myjob1","myjob2"]'
@Piduna哪个“子模块变量”?您的问题中没有任何模块。