-
-
Notifications
You must be signed in to change notification settings - Fork 740
Closed
Description
Description
Using for_each
does not work when trying to create multiple lambdas based upon some var of type list(string)
Versions
-
Terraform:
v0.15.0 -
Provider(s):
- provider registry.terraform.io/hashicorp/aws v3.37.0
- provider registry.terraform.io/hashicorp/external v2.1.0
- provider registry.terraform.io/hashicorp/local v2.1.0
- provider registry.terraform.io/hashicorp/null v3.1.0
- provider registry.terraform.io/hashicorp/random v3.1.0
-
Module:
module "lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "1.47.0"
# insert the 28 required variables here
}
Reproduction
Steps to reproduce the behavior:
- set variable of
type list(string
- use latest tf and module version for lambda
- try to loop over vars to create more than 1 lambda using the same module
- errors
Code Snippet to Reproduce
variables.tf
variable "my-var" {
type = list(string)
}
terraform.auto.tfvars
my-var=["one","two","three"]
main.tf
module "lambda_function" {
version = "1.47.0"
source = "terraform-aws-modules/lambda/aws"
for_each = toset(var.my-var)
function_name = "function-name-${each.key}"
description = "My Description"
handler = "index.handler"
runtime = "nodejs14.x"
create_package = false
s3_existing_package = {
bucket = "existing-lambda-zip-in-s3"
key = "lambda/${each.key}/index.zip"
}
}
Expected behavior
Create lambda for each of the values in the var, e.g.
Creates 3 lambdas, per the defined variable
Actual behavior
Error returned:
Error: error creating Lambda Function (1): ValidationException:
│ status code: 400, request id: 9a97feb4-b486-4469-ac0f-d5992faa27c8
│
│ on .terraform/modules/lambda_function/main.tf line 14, in resource "aws_lambda_function" "this":
│ 14: resource "aws_lambda_function" "this" {
Terminal Output Screenshot(s)
Additional context
Plan comes back clean, only after apply do you get these errors.
I believe this is due to the count in the module not expecting more than one, but haven't dug into that code quite yet
Metadata
Metadata
Assignees
Labels
No labels