Skip to content

Commit

Permalink
Trigger rebuild when Lambda utils code changes (#40)
Browse files Browse the repository at this point in the history
* Trigger pipelines on changes to lambda utils
* Terraform format
* Remove archive folder and use fileset to detect changes
* Address PR comments
* Remove unnecessary toset function
  • Loading branch information
paulschwarzenberger authored Mar 8, 2024
1 parent 1b67e69 commit 4216c15
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ecdsa_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
- name: cache built python modules
uses: actions/cache@v4
with:
key: modules_terraform-aws-ca-lambda_build_${{ hashFiles('./modules/terraform-aws-ca-lambda/lambda_code/**') }}_py${{ steps.setup_python.outputs.python-version }}
key: modules_terraform-aws-ca-lambda_build_${{ hashFiles('./modules/terraform-aws-ca-lambda/lambda_code/**') }}_${{ hashFiles('./modules/terraform-aws-ca-lambda/utils/**') }}_py${{ steps.setup_python.outputs.python-version }}
path: ./modules/terraform-aws-ca-lambda/build

- name: terraform plan
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rsa_public_crl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: cache built python modules
uses: actions/cache@v4
with:
key: modules_terraform-aws-ca-lambda_build_${{ hashFiles('./modules/terraform-aws-ca-lambda/lambda_code/**') }}_py${{ steps.setup_python.outputs.python-version }}
key: modules_terraform-aws-ca-lambda_build_${{ hashFiles('./modules/terraform-aws-ca-lambda/lambda_code/**') }}_${{ hashFiles('./modules/terraform-aws-ca-lambda/utils/**') }}_py${{ steps.setup_python.outputs.python-version }}
path: ./modules/terraform-aws-ca-lambda/build

- name: terraform plan
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.idea
.vs
.venv
.zip
*.src.zip
__pycache__
.terraform.lock.hcl
.terraform.tfstate
Expand Down
Empty file.
14 changes: 6 additions & 8 deletions modules/terraform-aws-ca-lambda/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
resource "null_resource" "install_python_dependencies" {
triggers = {
source_archive_checksum = data.archive_file.lambda_source.output_base64sha256
# detect changes to Lambda code
lambda_code_sha256 = sha256(join("", [for f in sort(tolist(fileset("${path.module}/lambda_code/${local.file_name}", "**"))) : filesha256("${path.module}/lambda_code/${local.file_name}/${f}")]))

# detect changes to files in utils directory
utils_sha256 = sha256(join("", [for f in sort(tolist(fileset("${path.module}/utils", "**"))) : filesha256("${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 @@ -22,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 4216c15

Please sign in to comment.