Warm tip: This article is reproduced from serverfault.com, please click

list-Terraform不起作用输入和环境变量

(list - Terraform does not work input and environment variables)

发布于 2020-11-30 07:25:35

我有一个glue jobaws我做了一个循环。

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请问你能帮帮我吗 ?我整夜想解决这个问题。

Questioner
Piduna
Viewed
0
Marcin 2020-11-30 16:13:18

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

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