Skip to content

Commit

Permalink
intermediate source code archive to check for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
new23d committed Mar 4, 2024
1 parent 268663f commit 5d208c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Empty file.
18 changes: 12 additions & 6 deletions modules/terraform-aws-ca-lambda/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "null_resource" "install_python_dependencies" {
triggers = {
always_run = timestamp()
source_archive_checksum = data.archive_file.lambda_source.output_base64sha256
}

provisioner "local-exec" {
Expand All @@ -19,16 +19,22 @@ 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]
depends_on = [null_resource.install_python_dependencies, data.archive_file.lambda_source]
type = "zip"
source_dir = "${path.module}/build/${local.file_name}"
output_path = "${path.module}/build/${local.file_name}.zip"
output_path = "${path.module}/archive/${local.file_name}.zip"
}

resource "aws_lambda_function" "lambda" {
filename = "${path.module}/build/${local.file_name}.zip"
source_code_hash = sha1(join("", [for f in fileset("${path.module}/lambda_code/${local.file_name}", "*") : filesha1("${path.module}/lambda_code/${local.file_name}/${f}")]))
filename = data.archive_file.lambda_zip.output_path
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
function_name = "${var.project}-${var.function_name}-${var.env}"
description = "${var.project} ${var.description}"
role = var.lambda_role_arn
Expand Down Expand Up @@ -71,4 +77,4 @@ resource "aws_lambda_permission" "lambda_invoke" {
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.lambda.function_name
principal = each.value
}
}

0 comments on commit 5d208c2

Please sign in to comment.