Hey guys,
could you help me with the following problem? I have a list(objects) and would like to hand over some variables within AWS lambda as environment variables.
variable "accounts" {
type = list(object({
name = string # Name of the AWS account
number = string # Number of the AWS account
blabla = string
}))
}
The lambda code is like this:
module "lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "4.18.0"
function_name = "test"
handler = "lambda_function.lambda_handler"
runtime = "python3.8"
source_path = ".lambda_function.py"
environment_variables = {
"foo" = "bar"
}
}
How could I transform the list into key-value pairs? I tried something like this but did not succeed:
locals {
key_value_tuples = {
for obj in var.accounts :
obj.name => obj.number
}
}
And in Lambda
environment_variables = {
"foo" = "bar",
for obj in local.key_value_tuples :
obj.key => obj.value
}
which resulted in the following:
│ Error: Unsupported attribute
│
│ on test.tf line 97, in module "lambda":
│ 97: obj.key => obj.value
│
│ Cant access attributes on a primitive-typed value (string).
Thanks in advance!