terraform-aws-modules / terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws
Apache License 2.0
909 stars 681 forks source link

Error creating lambda: Could not locate source_path "null" #523

Closed darioackermann closed 8 months ago

darioackermann commented 9 months ago

Description

terraform plan fails with

Plan: 4 to add, 0 to change, 0 to destroy.
╷
│ Error: invalid value for name (must match [\w+=,.@-])
│
│   with module.lambda.aws_iam_role.lambda[0],
│   on .terraform\modules\lambda\iam.tf line 97, in resource "aws_iam_role" "lambda":
│   97:   name                  = local.role_name
│
╵
╷
│ Error: invalid value for name (must match [\w+=,.@-])
│
│   with module.lambda.aws_iam_policy.logs[0],
│   on .terraform\modules\lambda\iam.tf line 137, in resource "aws_iam_policy" "logs":
│  137:   name   = "${local.policy_name}-logs"
│
╵
╷
│ Error: External Program Execution Failed
│
│   with module.lambda.data.external.archive_prepare[0],
│   on .terraform\modules\lambda\package.tf line 10, in data "external" "archive_prepare":
│   10:   program = [local.python, "${path.module}/package.py", "prepare"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: C:\Users\a\AppData\Local\Programs\Python\Python310\python.exe
│ Error Message: Could not locate source_path "null".  Paths are relative to directory where `terraform plan` is being
│ run ("C:\Users\a\easteregg\terraform")
│
│ State: exit status 1

My issue is listed, here, but it was closed https://github.com/terraform-aws-modules/terraform-aws-lambda/issues/440

Versions

Reproduction Code [Required]

module "lambda" {
  source  = "terraform-aws-modules/lambda/aws"
  version = "6.5.0"
}

# ...

module "lambda_function" {
  source = "terraform-aws-modules/lambda/aws"

  function_name = "easteregg"
  handler       = "app.lambda_handler"
  runtime       = "nodejs20.x"

  role_name = "easteregg"

  source_path      = "${path.module}/../src"

}

Steps to reproduce the behavior:

Expected behavior

Actual behavior

Additional context

This is happening on Windows

yiskaneto commented 8 months ago

I encountered some issues related to source_path when I updated to release v7.0.0 while using aws provider version 5.24.0, I'm not saying this will solve your issues but in my case a bunch of errors went away when I updated the aws provider to version 5.33.0

antonbabenko commented 8 months ago

This code is wrong because there are not enough variables specified:

module "lambda" {
  source  = "terraform-aws-modules/lambda/aws"
  version = "6.5.0"
}

Please take a look at the examples for real and working examples.

github-actions[bot] commented 7 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.