Skip to content

Commit

Permalink
Remove archive folder and use fileset to detect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulschwarzenberger committed Mar 8, 2024
1 parent 2fc6466 commit 48195dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Empty file.
12 changes: 3 additions & 9 deletions modules/terraform-aws-ca-lambda/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
resource "null_resource" "install_python_dependencies" {
triggers = {
# detect changes to Lambda code
source_archive_checksum = data.archive_file.lambda_source.output_base64sha256
lambda_code_sha256 = sha256(join("", sort([for f in fileset("${path.module}/lambda_code/${local.file_name}", "**") : filesha1("${path.module}/lambda_code/${local.file_name}/${f}")])))

# detect changes to files in utils directory
dir_sha1 = sha1(join("", [for f in fileset("${path.module}/utils", "**") : filesha1("${path.module}/utils/${f}")]))
utils_sha256 = sha256(join("", sort([for f in fileset("${path.module}/utils", "**") : filesha1("${path.module}/utils/${f}")])))

# static value (true) if present, variable value (timestamp()) when not present. (so the 'false' state isn't static and forces a build by change of state whenever so. a static false value doesn't force change of state.)
build_already_present = fileexists("${path.module}/build/${local.file_name}/__init__.py") ? true : timestamp()
Expand All @@ -26,17 +26,11 @@ resource "null_resource" "install_python_dependencies" {
}
}

data "archive_file" "lambda_source" {
type = "zip"
source_dir = "${path.module}/lambda_code/${local.file_name}"
output_path = "${path.module}/archive/${local.file_name}.src.zip"
}

data "archive_file" "lambda_zip" {
depends_on = [null_resource.install_python_dependencies]
type = "zip"
source_dir = "${path.module}/build/${local.file_name}"
output_path = "${path.module}/archive/${local.file_name}.zip"
output_path = "${path.module}/build/${local.file_name}.zip"
}

resource "aws_lambda_function" "lambda" {
Expand Down

0 comments on commit 48195dc

Please sign in to comment.