A conditional for_each for a data source

Hi,
I am trying to add layers dynamically to a set of lambdas, I have used aws_lambda_layer_version to get the latest layer. However, the issue which I am facing is for the lambda for which I don’t want a layer to be added. If I don’t add any value or null, I am getting below error.

//ERROR
layer_name = each.value[“layer_name”]
The argument “layer_name” is required, but no definition was found.

###— Code example—
//lambda.tf
data “aws_lambda_layer_version” “existing” {
for_each = var.function_name
layer_name = each.value[“layer_name”]
}
module “lambda” {
depends_on = [module.lambda_role]

source = "./modules/lambda"
function_name = var.function_name
retention_period = var.retention_period
subnet_ids = var.subnet_ids
security_group_ids = var.security_group_ids    
role = module.lambda_role.lambda_role_arn
layers = [data.aws_lambda_layer_version.existing[each.key].arn]

//tfvars

function_name = {
“python-lambda” = {
# --------- lambda variables values -----------
“filename” = “ppython-lambda2.zip”
“handler” = “lambda_function.lambda_handler”
“runtime” = “python3.9”
“memory_size” = “512”
“set_timeout” = “900”
“layer_name” = “commonLayer”
},
“python-lambda2” = {
# --------- lambda variables values -----------
“filename” = “python-lambda2.zip”
“handler” = “lambda_function.lambda_handler”
“runtime” = “python3.9”
“memory_size” = “512”
“set_timeout” = “900”
“reserved_concurrent_executions” = “10”
“maximum_retry_attempts” = “2”
“maximum_event_age_in_seconds” = “600”
“layer_name” = “” #No layer to be added with this lambda
}