forked from claranet/terraform-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.tf
37 lines (32 loc) · 1.22 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
# 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" {
program = ["${path.module}/hash.py"]
query = {
runtime = var.runtime
source_path = var.source_path
build_script = coalesce(var.build_script, "${path.module}/build.py")
}
}
# Build the zip archive whenever the filename changes.
resource "null_resource" "archive" {
triggers = {
filename = data.external.archive.result["filename"]
}
provisioner "local-exec" {
command = data.external.archive.result["build_command"]
}
}
# 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" {
program = ["${path.module}/built.py"]
query = {
build_command = data.external.archive.result["build_command"]
filename_old = null_resource.archive.triggers["filename"]
filename_new = data.external.archive.result["filename"]
}
}