From 6d266ee7e9cfcbbeac0f2a0730e199b7ffcc56fb Mon Sep 17 00:00:00 2001 From: Ryan Ragnell Date: Thu, 23 Oct 2025 14:14:57 -0500 Subject: [PATCH 1/3] fix: prevent double-zipping when using poetry_install/pip_requirements/npm_requirements When poetry_install, pip_requirements, or npm_requirements are enabled, the dependency managers handle zipping their installed packages correctly. However, the module was also unconditionally zipping the original source path, causing both the dependencies AND filtered source files to be included in the final zip. This fix makes the source path zip step conditional - it only runs when NOT using dependency managers, preventing the double-zipping issue. Fixes issue where patterns were ineffective at excluding source files when poetry_install was enabled. --- package.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.py b/package.py index 74af6e7c..7dbf4e44 100644 --- a/package.py +++ b/package.py @@ -875,7 +875,10 @@ def commands_step(path, commands): required=True, tmp_dir=claim.get("npm_tmp_dir"), ) - if path: + + # Only zip the source path if not using dependency managers + # (pip/poetry/npm handle their own zipping) + if path and not (pip_requirements or poetry_install or npm_requirements): path = os.path.normpath(path) step("zip", path, prefix) if patterns: From 5343a88b09d6725a4b7a10393af3e0e56abdc046 Mon Sep 17 00:00:00 2001 From: Ryan Ragnell Date: Thu, 23 Oct 2025 14:26:39 -0500 Subject: [PATCH 2/3] chore: Fix trailing whitespace --- package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.py b/package.py index 7d79f709..da6dc223 100644 --- a/package.py +++ b/package.py @@ -880,7 +880,7 @@ def commands_step(path, commands): required=True, tmp_dir=claim.get("npm_tmp_dir"), ) - + # Only zip the source path if not using dependency managers # (pip/poetry/npm handle their own zipping) if path and not (pip_requirements or poetry_install or npm_requirements): From 4747847dc08a429b95c4dfff7cacac9ac21d84b7 Mon Sep 17 00:00:00 2001 From: Ryan Ragnell Date: Thu, 23 Oct 2025 14:33:10 -0500 Subject: [PATCH 3/3] docs: Add example demonstrating patterns with poetry_install Shows how to use patterns to exclude source files while keeping only poetry configuration files when using poetry_install. --- examples/build-package/main.tf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/build-package/main.tf b/examples/build-package/main.tf index ec843b68..28828cfe 100644 --- a/examples/build-package/main.tf +++ b/examples/build-package/main.tf @@ -471,6 +471,15 @@ module "lambda_layer_poetry" { path = "${path.module}/../fixtures/python-app-poetry" poetry_install = true poetry_tmp_dir = "${path.cwd}/../fixtures" + # Patterns work correctly with poetry_install - only poetry files are needed + # The installed dependencies will be in the layer, but source files will be excluded + patterns = [ + "!ignore_please.txt", # Exclude this file + "!index.py", # Exclude source code + "pyproject.toml", # Include poetry config + "poetry.lock", # Include lock file + "poetry.toml" # Include poetry settings + ] } ] hash_extra = "extra-hash-to-prevent-conflicts-with-module.package_dir"