I have a glue job
in aws
.
I made a loop.
In variables.tf
variable "list_of_jobs" {
type = list(string)
default = ["myjob1","myjob2","myjob3"]
}
In 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"
}
}
In main.tf
variable "region" {}
variable "list_of_jobs" {}
module "my_glue" {
source = "../terraform-glue"
region = var.region
list_of_jobs = var.list_of_jobs
}
This loop works fine, and I have 3 glue jobs
after execution of terraform apply
.
The problem, when I am trying to make:
export TF_VAR_list_of_jobs='["myjob1","myjob2","myjob3"]'
In this case, when I am making terraform apply
, I am receiving this:
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.
Input variables, does not work too. Only variable from variables.tf
. Could You help me please ? I am trying to resolve this during all night.
It does not work because you need to provide type constrain for your complex variable if you want to pass it though env variables:
variable "list_of_jobs" {
type = list(string)
default = ["myjob1","myjob2","myjob3"]
}
variable "list_of_jobs" { type = list(string) }
I did this, but in a resultlist of string required
@Piduna So provide the list of strings, this is what your
list_of_jobs
is.@Piduna You can also drop the string from type, and just use
type = list
if you want. Nevertheless, type must be present for complex types, as your list.The given value is not suitable for child module variable "list_of_job" defined
In my variables.tfvariable "list_of_jobs" { type = list # default = ["myjob1","myjob2","myjob3"] }
In my main.tf ` variable "list_of_jobs" {} ` I am makingterraform apply -var='list_of_jobs=["myjob1","myjob2"]'
@Piduna Which "child module variable"? You don't have any modules in your question.