Deploy multiple lambda functions through terraform

Viewed 651

Trying to deploy multiple lambda functions through terraform but getting error message. i have the lambda code in the s3 bucket. below is my code.

Error: Unbalanced parentheses on main.tf , in resource "aws_lambda_function" "test_lambda": function_name = (for fname in var.lambda_function_names: fname.split(".")[0] if fname == var.lambda_function_names[count.index]) Expected a closing parenthesis to terminate the expression.

variable "lambda_function_names"{
    default = [
        "test1.py",
        "test2.py"
    ]
} 



resource "aws_lambda_function" "test_lambda" {
  count = length(var.lambda_function_names) > 0 ? length(var.lambda_function_names) : 0
  s3_bucket="test-bucket"
  s3_key= "lambda_source_code/${var.lambda_function_names[count.index]}"
  function_name = for fname in var.lambda_function_names: fname.split(".")[0] if fname == var.lambda_function_names[count.index])
  role          = "arn:aws:iam::12344566676:role/lambda-role"
  handler       = "${var.lambda_function_names[count.index]}.lambda_handler"
  runtime = "python3.8"
}
0 Answers
Related