I'm using aws version 3.50.0, but with for_each to read from _variables.tf. My main.tf is given below. When I comment out environment section as shown below, everything works. But how to add environment variables? When I uncomment and run the plan it throws this error:
│ Error: Unsupported block type
│
│ on main.tf line 22, in module "lambda_function":
│ 22: environment {
│
│ Blocks of type "environment" are not expected here.
│
│ make: *** [Makefile:44: plan] Error 1
______________________________________________________
locals {
functions = {
for function in local.workspace:
function.name => function
}
}
module "lambda_function" {
source = "terraform-aws-modules/lambda/aws"
for_each = local.functions
function_name = "${element(split("-", terraform.workspace), 4)}-${each.value.name}"
description = lookup(each.value, "description", "Not applicable")
handler = "${each.value.name}.lambda_handler"
memory_size = 128
reserved_concurrent_executions = lookup(each.value, "reserved_concurrent_executions", 5)
source_path = "${each.value.name}.py"
runtime = "python3.8"
# environment {
# variables = {
# LOTJM_ENV = "${element(split("-", terraform.workspace), 4)}"
# }
# }
tags = {
Name = "${element(split("-", terraform.workspace), 4)}-${each.value.name}"
}
}
environment_variablesvariable / parameter instead, not a block and not an arbitrarily named one.environment_variables. That should fix the issue for you. I also have a terraform module for lambda that you can use if you need help: github.com/tomarv2/terraform-aws-lambda