Skip to content

google cloud functions cannot get updates on the build_environment_variables #18284

Open
@leandrogoe

Description

@leandrogoe

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version & Provider Version(s)

Terraform v1.4.0
on darwin_arm64

  • provider registry.terraform.io/hashicorp/archive v2.2.0
  • provider registry.terraform.io/hashicorp/google v4.30.0
  • provider registry.terraform.io/hashicorp/google-beta v4.30.0
  • provider registry.terraform.io/hashicorp/random v3.6.2

Affected Resource(s)

google_cloudfunctions_function

Terraform Configuration

variable "some_variable" {
  description = "variable required at build time"
}

resource "google_storage_bucket" "google_functions_bucket" {
  name     = "${terraform.workspace}-functions"
  location = "US"
}

data "archive_file" "my_function" {
  type        = "zip"
  source_dir  = "${path.root}/cloud_functions/my_function"
  output_path = "/tmp/my_function.zip"
}

resource "google_storage_bucket_object" "cache_my_function" {
  name   = "${data.archive_file.my_function.output_md5}.zip"
  bucket = google_storage_bucket.google_functions_bucket.name
  source = "/tmp/my_function.zip"
}

resource "google_cloudfunctions_function" "my_simple_function" {
  name        = "my-simple-function"
  runtime     = "nodejs18"

  available_memory_mb          = 128
  source_archive_bucket        = google_storage_bucket.google_functions_bucket.name
  source_archive_object        = google_storage_bucket_object.cache_my_function.name
  trigger_http                 = true
  https_trigger_security_level = "SECURE_ALWAYS"
  timeout                      = 300
  entry_point                  = "someMethod"

  build_environment_variables = {
    SOME_ENV_VAR = var.some_variable
  }
}

Debug Output

No response

Expected Behavior

When changing the value of any of build_environment_variables terraform should be able to handle it properly

Actual Behavior

When changing the value of any of build_environment_variables for an EXISTING cloud function terraform fails:

Error: Error while updating cloudfunction configuration: googleapi: Error 400: The request has errors
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.BadRequest",
│     "fieldViolations": [
│       {
│         "description": "build environment variables are not supported by this runtime",
│         "field": "build_environment_variables"
│       }
│     ]
│   }
│ ]
│ , badRequest
│ 
│   with module.pgp_decryption.google_cloudfunctions_function.my_simple_function,
│   on main.tf line 17, in resource "google_cloudfunctions_function" "my_simple_function":
│   17: resource "google_cloudfunctions_function" "my_simple_function" {
│ 

Looking at the logs, it appears that there is a problem with the PATCH method of the Google API. Whenever you try to update the build_environment_variables you also need to include the runtime in the update mask for it to succeed.

Steps to reproduce

  1. terraform apply -var="some_variable=1"
  2. terraform apply -var="some_variable=2"

The first apply succeeds, but the second one fails with the error above.

Important Factoids

No response

References

No response

b/343970055

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions