Terraform 1.4.5: working with 'Invalid Index' scenarios with List Variable When Using for_each on Modules
I'm working on a personal project and I am experiencing an 'Invalid Index' behavior when trying to use a list variable with the `for_each` meta-argument in a module block... I'm working on a Terraform configuration that provisions multiple AWS Lambda functions based on the names provided in a list. Here is a snippet of my code: ```hcl variable "lambda_names" { description = "List of Lambda function names" type = list(string) } module "lambda" { source = "./modules/lambda" for_each = var.lambda_names function_name = each.value } ``` The module `./modules/lambda` has a simple configuration to create the Lambda function: ```hcl resource "aws_lambda_function" "this" { function_name = var.function_name handler = "index.handler" runtime = "nodejs14.x" role = aws_iam_role.lambda_role.arn source_code_hash = filebase64sha256("./lambda.zip") } ``` Despite defining the variable `lambda_names` as a list of strings when I run `terraform apply`, I am getting the following behavior: ``` behavior: Invalid index on main.tf line 10, in module "lambda": 10: for_each = var.lambda_names The given key does not identify an element in this collection value. ``` I have verified that the `lambda_names` variable is being set correctly in my `terraform.tfvars` file: ```hcl lambda_names = ["lambdaA", "lambdaB", "lambdaC"] ``` I have also tried reinitializing the Terraform workspace and checking for any typos in the variable declaration, but the behavior continues. Could the scenario be related to the way I'm passing the list to the `for_each` argument, or perhaps there's something wrong in the module's implementation? Any insights would be appreciated! I recently upgraded to Hcl 3.11. Thanks in advance!