Skip to content

Commit 584a43e

Browse files
authored
Write cached zip archive to file before uploading (#26)
## Summary: Terraform managed to trick me again. I was able to apply this from my machine, but it failed in CI. It seems the google storage upload isn't happy with pushing a zip using the `content` field. Instead, let's write the zip to file during the apply, then push that file. Issue: INFRA-XXXX ## Test plan: I again ran this and triple-checked that the zip was actually pushed and deployed as a cloud function. See the latest revision [here](https://console.cloud.google.com/run/detail/us-central1/check-sentry-rate-limiting/revisions?project=khan-internal-services). Author: jwbron Reviewers: copilot-pull-request-reviewer[bot], jwbron, csilvers, MiguelCastillo Required Reviewers: Approved By: csilvers Checks: ✅ 7 checks were successful, ⏭️ 2 checks have been skipped Pull Request URL: #26
1 parent e51f43a commit 584a43e

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • terraform/modules/scheduled-job

terraform/modules/scheduled-job/main.tf

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ data "local_sensitive_file" "function_archive_content" {
5656
depends_on = [data.archive_file.function_archive]
5757
}
5858

59+
# Write the embedded zip content to a file
60+
# This recreates the zip file using the content embedded in the tfplan binary
61+
# This supports running an `apply` after a `plan` on a different machine.
62+
resource "local_file" "function_archive_for_upload" {
63+
count = var.execution_type == "function" ? 1 : 0
64+
65+
filename = "${path.module}/${var.job_name}-function.zip"
66+
content_base64 = data.local_sensitive_file.function_archive_content[0].content_base64
67+
file_permission = "0644"
68+
}
69+
5970
# Upload function archive to storage bucket (only for Cloud Functions)
6071
# The object name includes the source code hash, ensuring:
6172
# 1. Cloud Function redeploys when source code changes (new hash = new object name)
@@ -64,9 +75,9 @@ data "local_sensitive_file" "function_archive_content" {
6475
resource "google_storage_bucket_object" "function_archive" {
6576
count = var.execution_type == "function" ? 1 : 0
6677

67-
name = "${var.job_name}-function-${data.archive_file.function_archive[0].output_sha}.zip"
68-
bucket = google_storage_bucket.function_bucket[0].name
69-
content = data.local_sensitive_file.function_archive_content[0].content
78+
name = "${var.job_name}-function-${data.archive_file.function_archive[0].output_sha}.zip"
79+
bucket = google_storage_bucket.function_bucket[0].name
80+
source = local_file.function_archive_for_upload[0].filename
7081
}
7182

7283
# PubSub topic for triggering the Cloud Function (only created when execution_type is "function")

0 commit comments

Comments
 (0)