Terraform 1.4.3: how to to Use `for_each` With Dynamic Blocks for AWS Lambda Environment Variables
I'm trying to create an AWS Lambda function using Terraform 1.4.3, and I want to set environment variables dynamically using a `for_each` loop within a dynamic block. However, I keep working with an behavior that says: `behavior: Invalid index`. I've defined my environment variables as a map and want to iterate over this map to set them up for my Lambda function. Hereβs the relevant portion of my configuration: ```hcl variable "env_vars" { type = map(string) default = { "VAR1" = "value1" "VAR2" = "value2" } } resource "aws_lambda_function" "my_lambda" { function_name = "my_lambda_function" runtime = "python3.8" handler = "lambda_function.lambda_handler" role = aws_iam_role.lambda_exec.arn environment { dynamic "variables" { for_each = var.env_vars content { key = variables.key value = variables.value } } } } ``` I've tried changing the structure a few times, but I always run into the same scenario. The behavior seems to stem from how I'm referencing `variables.key` and `variables.value`. I've tried using `key` and `value` directly, but the behavior continues. Does anyone have insights into properly using dynamic blocks with `for_each` to set environment variables on an AWS Lambda function? Any help would be greatly appreciated!