Skip to content

Commit 0b0dc9c

Browse files
authored
Merge pull request #3 from parknow/feature/nodeps-pip-parameter
--no-deps pip parameter
2 parents 8e018cc + 8a939ff commit 0b0dc9c

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ change.
1616
```
1717
module "python_lambda_archive" {
1818
source = "rojopolis/lambda-python-archive/aws"
19-
src_dir = "${path.module}/python"
20-
output_path = "${path.module}/lambda.zip"
19+
20+
src_dir = "${path.module}/python"
21+
output_path = "${path.module}/lambda.zip"
22+
install_dependencies = false
2123
}
2224
2325
resource "aws_iam_role" "iam_for_lambda" {

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
data "external" "lambda_archive" {
22
program = ["python3", "${path.module}/scripts/build_lambda.py"]
33
query = {
4-
src_dir = "${var.src_dir}"
5-
output_path = "${var.output_path}"
4+
src_dir = var.src_dir
5+
output_path = var.output_path
6+
install_dependencies = var.install_dependencies
67
}
78
}

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
output "archive_path" {
22
description = "Path of the archive file."
3-
value = "${data.external.lambda_archive.result.archive}"
3+
value = data.external.lambda_archive.result.archive
44
}
55

66
output "source_code_hash" {
77
description = "Base64 encoded SHA256 hash of the archive file."
8-
value = "${data.external.lambda_archive.result.base64sha256}"
8+
value = data.external.lambda_archive.result.base64sha256
99
}

scripts/build_lambda.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import tempfile
1414
import zipfile
1515

16-
def build(src_dir, output_path):
16+
def build(src_dir, output_path, install_dependencies):
1717
with tempfile.TemporaryDirectory() as build_dir:
1818
copy_tree(src_dir, build_dir)
1919
if os.path.exists(os.path.join(src_dir, 'requirements.txt')):
@@ -24,7 +24,8 @@ def build(src_dir, output_path):
2424
'install',
2525
'--ignore-installed',
2626
'--target', build_dir,
27-
'-r', os.path.join(build_dir, 'requirements.txt')],
27+
'-r', os.path.join(build_dir, 'requirements.txt'),
28+
*(['--no-deps'] if install_dependencies == 'false' else [])],
2829
check=True,
2930
stdout=subprocess.DEVNULL,
3031
)
@@ -71,5 +72,5 @@ def get_hash(output_path):
7172
logging.basicConfig(level='DEBUG')
7273
query = json.loads(sys.stdin.read())
7374
logging.debug(query)
74-
archive = build(query['src_dir'], query['output_path'])
75-
print(json.dumps({'archive': archive, "base64sha256":get_hash(archive)}))
75+
archive = build(query['src_dir'], query['output_path'], query['install_dependencies'])
76+
print(json.dumps({'archive': archive, 'base64sha256':get_hash(archive)}))

variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
variable "src_dir" {
22
description = "Path to root of Python source to package."
3-
type = "string"
3+
type = string
44
}
55

66
variable "output_path" {
77
description = "The output of the archive file."
8-
type = "string"
8+
type = string
9+
}
10+
11+
variable "install_dependencies" {
12+
description = "Whether to install pip dependecies"
13+
type = bool
14+
default = true
915
}

0 commit comments

Comments
 (0)