Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger rebuild when Lambda utils code changes #40

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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