If you have an aws_lambda_function block that needs to make use of environment variables, then you can simply do the following:

resource "aws_lambda_function" "test_lambda" {
  filename         = "lambda_function_payload.zip"
  function_name    = "lambda_function_name"
  runtime          = "python3.9"
  ...

  environment {
    variables = {
      api_key = "secret-key"
    }
  }
}

The above example creates an environment variable called api_key with a value of secret-key