forked from claranet/terraform-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.tf
47 lines (39 loc) · 1.5 KB
/
archive.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Generates a filename for the zip archive based on the contents of the files
# in source_path. The filename will change when the source code changes.
data "external" "archive" {
count = var.enabled ? 1 : 0
program = ["python", "${path.module}/hash.py"]
query = {
build_command = var.build_command
build_paths = jsonencode(var.build_paths)
module_relpath = path.module
runtime = var.runtime
source_path = var.source_path
}
}
# Build the zip archive whenever the filename changes.
resource "null_resource" "archive" {
count = var.enabled ? 1 : 0
triggers = {
filename = lookup(data.external.archive[0].result, "filename")
}
provisioner "local-exec" {
command = lookup(data.external.archive[0].result, "build_command")
working_dir = path.module
}
}
# Check that the null_resource.archive file has been built. This will rebuild
# it if missing. This is used to catch situations where the Terraform state
# does not match the Lambda function in AWS, e.g. after someone manually
# deletes the Lambda function. If the file is rebuilt here, the build
# output is unfortunately invisible.
data "external" "built" {
count = var.enabled ? 1 : 0
program = ["python", "${path.module}/built.py"]
query = {
build_command = lookup(data.external.archive[0].result, "build_command")
filename_old = lookup(null_resource.archive[0].triggers, "filename")
filename_new = lookup(data.external.archive[0].result, "filename")
module_relpath = path.module
}
}