Skip to content

Commit

Permalink
don't compute checksum in cloud function module for static bundles (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoo authored Jun 13, 2024
1 parent 97d77d2 commit cb5b369
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
2 changes: 1 addition & 1 deletion modules/cloud-function-v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ The Cloud Function bundle can be configured via the `bundle_config` variable, so

If a `zip` archive is already available, simply set the archive path in `bundle_config.path`. If a dynamically generated archive is needed, set `bundle_config.path` to the source folder path, then optionally configure the path where the archive will be created, and any exclusions needed in the archive.

In order to help prevent `archive_zip.output_md5` from changing cross platform (e.g. Cloud Build vs your local development environment), you'll have to make sure that the files included in the zip are always the same.
If you use a folder and dynamic archive bundling, be mindful that the MD5 checksum of the generated `zip` file does not change across environments (e.g. Cloud Build vs your local development environment), by ensuring that the files in the folder are always the same.

```hcl
module "cf-http" {
Expand Down
15 changes: 4 additions & 11 deletions modules/cloud-function-v1/bundle.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

locals {
bundle = {
md5 = try(
data.archive_file.bundle[0].output_md5,
data.local_file.bundle[0].content_md5
name = try(
"bundle-${data.archive_file.bundle[0].output_md5}.zip",
basename(var.bundle_config.path)
)
path = try(
data.archive_file.bundle[0].output_path,
Expand Down Expand Up @@ -57,7 +57,7 @@ resource "google_storage_bucket" "bucket" {
}

resource "google_storage_bucket_object" "bundle" {
name = "bundle-${local.bundle.md5}.zip"
name = local.bundle.name
bucket = local.bucket
source = local.bundle.path
}
Expand All @@ -72,10 +72,3 @@ data "archive_file" "bundle" {
output_file_mode = "0644"
excludes = var.bundle_config.excludes
}

data "local_file" "bundle" {
count = (
try(fileexists(var.bundle_config.path), null) == null ? 0 : 1
)
filename = var.bundle_config.path
}
2 changes: 1 addition & 1 deletion modules/cloud-function-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ The Cloud Function bundle can be configured via the `bundle_config` variable, so

If a `zip` archive is already available, simply set the archive path in `bundle_config.path`. If a dynamically generated archive is needed, set `bundle_config.path` to the source folder path, then optionally configure the path where the archive will be created, and any exclusions needed in the archive.

In order to help prevent `archive_zip.output_md5` from changing cross platform (e.g. Cloud Build vs your local development environment), you'll have to make sure that the files included in the zip are always the same.
If you use a folder and dynamic archive bundling, be mindful that the MD5 checksum of the generated `zip` file does not change across environments (e.g. Cloud Build vs your local development environment), by ensuring that the files in the folder are always the same.

```hcl
module "cf-http" {
Expand Down
15 changes: 4 additions & 11 deletions modules/cloud-function-v2/bundle.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

locals {
bundle = {
md5 = try(
data.archive_file.bundle[0].output_md5,
data.local_file.bundle[0].content_md5
name = try(
"bundle-${data.archive_file.bundle[0].output_md5}.zip",
basename(var.bundle_config.path)
)
path = try(
data.archive_file.bundle[0].output_path,
Expand Down Expand Up @@ -57,7 +57,7 @@ resource "google_storage_bucket" "bucket" {
}

resource "google_storage_bucket_object" "bundle" {
name = "bundle-${local.bundle.md5}.zip"
name = local.bundle.name
bucket = local.bucket
source = local.bundle.path
}
Expand All @@ -72,10 +72,3 @@ data "archive_file" "bundle" {
output_file_mode = "0644"
excludes = var.bundle_config.excludes
}

data "local_file" "bundle" {
count = (
try(fileexists(var.bundle_config.path), null) == null ? 0 : 1
)
filename = var.bundle_config.path
}

0 comments on commit cb5b369

Please sign in to comment.