terraform-aws-modules/terraform-aws-lambda

npm_requirements does not run `npm install` on `terraform apply`

yepengfan opened this issue · 3 comments

Hi I am using the latest version of Terraform.

Terraform v1.2.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/aws v4.24.0
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/local v2.2.3
+ provider registry.terraform.io/hashicorp/null v3.1.1
+ provider registry.terraform.io/hashicorp/random v3.3.2

This is my code block

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

  create_layer = true

  layer_name          = "lambda-layer"
  description         = "Lmabda layer"
  compatible_runtimes = ["nodejs14.x", "nodejs12.x"]
  source_path = [
    {
      path = "src/lambda_layer/nodejs",
      npm_requirements = true
    }
  ]
}

This does not raise an error, but the node_modules folder is not created on deployment.

Apart from that, I also tried to use commands

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

  create_layer = true

  layer_name          = "lambda-layer"
  description         = "Lmabda layer"
  compatible_runtimes = ["nodejs14.x", "nodejs12.x"]
  source_path = [
    {
      path = "src/lambda_layer/nodejs",
      commands = [
        "npm install",
        ":zip"
      ]
    }
  ]
}

When I run this code block, the required node_modules folder is generated, but it raises an error that complains a zip file does not exist. However, I can find the file in the builds folder. I feel this is possibly a bug to fix.

 zip: adding: node_modules/xmlbuilder/lib/XMLDeclaration.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLDocType.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLDocument.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLDocumentCB.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLElement.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLNode.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLProcessingInstruction.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLRaw.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLStreamWriter.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLStringWriter.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLStringifier.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLText.js
│ zip: adding: node_modules/xmlbuilder/lib/XMLWriterBase.js
│ zip: adding: node_modules/xmlbuilder/lib/index.js
│ Traceback (most recent call last):
│   File ".terraform/modules/api.add_users_lambda.lambda_layer.lambda_layer/package.py", line 1389, in <module>
│     main()
│   File ".terraform/modules/api.add_users_lambda.lambda_layer.lambda_layer/package.py", line 1385, in main
│     exit(args.command(args))
│   File ".terraform/modules/api.add_users_lambda.lambda_layer.lambda_layer/package.py", line 1277, in build_command
│     bpm.execute(build_plan, zs, query)
│   File ".terraform/modules/api.add_users_lambda.lambda_layer.lambda_layer/package.py", line 318, in __exit__
│     self.close()
│   File ".terraform/modules/api.add_users_lambda.lambda_layer.lambda_layer/package.py", line 308, in close
│     os.replace(self._tmp_filename, self.filename)
│ FileNotFoundError: [Errno 2] No such file or directory: 'builds/5e6cdfe1b4b62259a5b315df3c2935b6037f6f3250f24bd3bffbf0ac570bbc73.zip.tmp' ->
│ 'builds/5e6cdfe1b4b62259a5b315df3c2935b6037f6f3250f24bd3bffbf0ac570bbc73.zip'

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

This issue was automatically closed because of stale in 10 days

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.