npm_requirements does not run npm install
bryant8317 opened this issue · 3 comments
Description
According to the documentation, npm_requirements controls whether npm install is run when building a package. However, it does not work correctly.
When setting source_path directly to the directory's path with package.json, the build plan it creates contains the npm step.
Terraform Snippet:
module "test-layer" {
source = "terraform-aws-modules/lambda/aws"
create_layer = true
build_in_docker = true
layer_name = "test-layer"
description = "test-npm-install"
runtime = "nodejs14.x"
compatible_runtimes = ["nodejs14.x"]
source_path = "src/test_package"
}
Build Plan:
{
"filename": "builds\\xxx.zip",
"runtime": "nodejs14.x",
"artifacts_dir": "builds",
"build_plan": [
["npm", "nodejs14.x", "src/test_package\\package.json", null, null],
["zip", "src/test_package", null]
],
"docker": {
"docker_additional_options": [],
"docker_build_root": "",
"docker_entrypoint": null,
"docker_file": "",
"docker_image": "",
"docker_pip_cache": null,
"with_ssh_agent": false
}
}
However, when I add npm_requiremetns and prefix_in_zip to the terraform template, the build plan no longer contains the npm step.
Terraform Snippet:
module "test-layer" {
source = "terraform-aws-modules/lambda/aws"
create_layer = true
build_in_docker = true
layer_name = "test-layer"
description = "test-npm-install"
runtime = "nodejs14.x"
compatible_runtimes = ["nodejs14.x"]
source_path = [
{
path = "src/test_package",
npm_requirements = true,
prefix_in_zip = "nodejs/"
}
]
}
Build Plan:
{
"filename": "builds\\xxxx.zip",
"runtime": "nodejs14.x",
"artifacts_dir": "builds",
"build_plan": [["zip", "src/test_package", "nodejs/"]],
"docker": {
"docker_additional_options": [],
"docker_build_root": "",
"docker_entrypoint": null,
"docker_file": "",
"docker_image": "",
"docker_pip_cache": null,
"with_ssh_agent": false
}
}
Versions
- Module version [Required]:
4.7.1 - Terraform version:
Terraform v1.3.5 - Provider version(s):
+ provider registry.terraform.io/hashicorp/aws v4.45.0 + provider registry.terraform.io/hashicorp/external v2.2.3 + provider registry.terraform.io/hashicorp/local v2.2.3 + provider registry.terraform.io/hashicorp/null v3.2.1
Reproduction Code [Required]
Run terraform plan
with the following template
module "test-layer" {
source = "terraform-aws-modules/lambda/aws"
create_layer = true
build_in_docker = true
layer_name = "test-layer"
description = "test-npm-install"
runtime = "nodejs14.x"
compatible_runtimes = ["nodejs14.x"]
source_path = [
{
path = "src/test_package",
npm_requirements = true,
prefix_in_zip = "nodejs/"
}
]
}
Expected behavior
I expect to see npm step in the build plan similar to below
{
"filename": "builds\\xxxx.zip",
"runtime": "nodejs14.x",
"artifacts_dir": "builds",
"build_plan": [
["npm", "nodejs14.x", "src/test_package\\package.json", null, null],
["zip", "src/test_package", "nodejs/"]
],
"docker": {
"docker_additional_options": [],
"docker_build_root": "",
"docker_entrypoint": null,
"docker_file": "",
"docker_image": "",
"docker_pip_cache": null,
"with_ssh_agent": false
}
}
Actual behavior
{
"filename": "builds\\xxxx.zip",
"runtime": "nodejs14.x",
"artifacts_dir": "builds",
"build_plan": [["zip", "src/test_package", "nodejs/"]],
"docker": {
"docker_additional_options": [],
"docker_build_root": "",
"docker_entrypoint": null,
"docker_file": "",
"docker_image": "",
"docker_pip_cache": null,
"with_ssh_agent": false
}
}
Additional context
I have checked package.py and found the following line
terraform-aws-lambda/package.py
Line 794 in 2e9aaa2
It seems like package.py is not getting the correct parameter (npm_requirements). In fact, when I add npm_package_json to my terraform template. The build plan behaves correctly as I expect.
module "test-layer" {
source = "terraform-aws-modules/lambda/aws"
create_layer = true
build_in_docker = true
layer_name = "test-layer"
description = "test-npm-install"
runtime = "nodejs14.x"
compatible_runtimes = ["nodejs14.x"]
source_path = [
{
path = "src/test_package",
npm_requirements = true,
npm_package_json = true,
prefix_in_zip = "nodejs/"
}
]
}
I think this line in package.py will need to be changed to
npm_requirements = claim.get('npm_requirements')
I will use npm_package_json as a workaround in the meanwhile
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