Cloud functions are not redeployed on code change

Hi,

I’m using cloudfunctions2_function, storing data in a cloud bucket.

data "archive_file" "archive" {
  type        = "zip"
  output_path = "${path.module}/app.zip"
  source_dir  = "${path.module}/.."
}

resource "google_storage_bucket" "bucket" {
  name     = "XXX"
  location = var.region
}

resource "google_storage_bucket_object" "archive" {
  name   = "XXXX"
  bucket = google_storage_bucket.bucket.name
  source = "${path.module}/app.zip"
}

when i define my function resource, I specify

storage_source {
        bucket = google_storage_bucket.bucket.name
        object = google_storage_bucket_object.archive.name
}

However, this configuration will not make Terraform redeploy the function when the code of my function changes. (I know this from logging and using gcloud functions deploy directly). How can i do so ?

I’ve tried specifying an env variable, but this does not change the code of the function deployed, it only updates the variable

      SOURCE_MD5_HASH = google_storage_bucket_object.archive.md5hash

When doing Terraform plan or apply, the google_storage_bucket_object.archive is correctly replaced, and I can check that the code in the bucket is updated.

My coworker pointed me to Updating Cloud Functions' source code requires changing zip path · Issue #1938 · hashicorp/terraform-provider-google · GitHub. In your example, the following might work:

resource "google_storage_bucket_object" "archive" {
  name   = "app-${data.archive_file.archive.output_sha256}.zip"
  bucket = google_storage_bucket.bucket.name
  source = data.archive_file.archive.output_path
}