Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List Terraform不支持输入和环境变量_List_Amazon Web Services_For Loop_Environment Variables_Terraform - Fatal编程技术网

List Terraform不支持输入和环境变量

List Terraform不支持输入和环境变量,list,amazon-web-services,for-loop,environment-variables,terraform,List,Amazon Web Services,For Loop,Environment Variables,Terraform,我在aws中有一个粘合作业。 我绕了一圈 在variables.tf中 variable "list_of_jobs" { type = list(string) default = ["myjob1","myjob2","myjob3"] } resource "aws_glue_job" "this" { for_each = toset(var.list_

我在
aws
中有一个
粘合作业
。 我绕了一圈

variables.tf中

variable "list_of_jobs" {
  type = list(string)
  default = ["myjob1","myjob2","myjob3"]
}

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"
  }
}
variable "region" {}
variable "list_of_jobs" {}

module "my_glue" {
  source = "../terraform-glue"
  region = var.region
  list_of_jobs = var.list_of_jobs
}
glue.tf中

variable "list_of_jobs" {
  type = list(string)
  default = ["myjob1","myjob2","myjob3"]
}

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"
  }
}
variable "region" {}
variable "list_of_jobs" {}

module "my_glue" {
  source = "../terraform-glue"
  region = var.region
  list_of_jobs = var.list_of_jobs
}
main.tf中

variable "list_of_jobs" {
  type = list(string)
  default = ["myjob1","myjob2","myjob3"]
}

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"
  }
}
variable "region" {}
variable "list_of_jobs" {}

module "my_glue" {
  source = "../terraform-glue"
  region = var.region
  list_of_jobs = var.list_of_jobs
}
这个循环运行良好,在执行
terraformapply
之后,我有3个
粘合作业。
问题是,当我试图做出以下决定时:

export TF_VAR_list_of_jobs='["myjob1","myjob2","myjob3"]'
在这种情况下,当我应用
地形时
,我收到以下信息:

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.


输入变量,也不起作用。仅变量来自
变量.tf
。你能帮我吗?我整晚都在试图解决这个问题。

它不起作用,因为如果要通过env变量传递复杂变量,需要为其提供类型约束:

variable "list_of_jobs" {
  type    = list(string)
  default = ["myjob1","myjob2","myjob3"]
}

您是否尝试过:
terraform apply-var='list_of_jobs=[“my-job2”,“my-job2”]'
只是为了确保它能以这种方式工作,可能tf不喜欢引用或其他东西是的,我尝试过。同样的结果。我很震惊,为什么它不工作?地形版?13.5版。在最新版本中,您可以尝试一些更老的版本,比如0.13.1甚至0.12.26吗?记住使用不同的状态后端
变量“list_of_jobs”{type=list(string)}
我这样做了,但是在结果
list of string required
@Piduna中提供字符串列表,这就是你的
list of_jobs
是什么。@Piduna你也可以从type中删除字符串,如果需要,只需使用
type=list
。但是,对于复杂类型,类型必须作为列表出现。
给定的值不适用于my variables.tf
variable“list_of_jobs”{type=list#default=[“myjob1”、“myjob2”、“myjob3”]
中定义的子模块变量“list_of_jobs”。tf`variable“list_of_of_jobs”{`I make
terraform apply-var='list_of_jobs=[“myjob1”,“myjob2”].
@Piduna哪个“子模块变量”?你的问题中没有任何模块。