hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.35k stars 1.75k forks source link

google_cloudfunctions_function does not detect change from sourceArchiveUrl to sourceUploadUrl #6137

Open preston-hf opened 4 years ago

preston-hf commented 4 years ago

Community Note

Terraform Version

Terraform v0.12.23

Affected Resource(s)

Terraform Configuration Files

resource "google_cloudfunctions_function" "myproject" {
  provider = google-beta
  project = module.myproject.project_id
  name        = "myproject"
  description = "myproject"
  runtime     = "python37"
  region      = "us-central1"
  service_account_email = google_service_account.myproject_service_account.email

  available_memory_mb   = 128
  source_archive_bucket = google_storage_bucket.function_source_bucket.name
  source_archive_object = google_storage_bucket_object.myproject_archive.name

  trigger_http          = true
  timeout               = 60
  entry_point           = "handle_http_request"
  environment_variables = {}

  lifecycle {
    ignore_changes = [labels]
  }
}

Debug Output

I can't post this for privacy reasons, but I can see the API response for the function returns the sourceUploadUrl which should be detected as a change since it originally was sourceArchiveUrl

Expected Behavior

Terraform should detect the drift from sourceArchiveUrl to sourceUploadUrl

Actual Behavior

Changes to source code are not detected

Steps to Reproduce

  1. Define a function that uses source_archive_bucket and source_archive_object to specify function source, apply config successfully.
  2. Use gcloud app deploy <function name> --source . or otherwise utilize the gcloud source upload functionality
  3. Run terraform plan, notice that no changes are detected. You may see that a label has been added but no changes will be detected to the source code.

References

b/274818913

venkykuberan commented 4 years ago

With request/response i see sourceArchiveUrl has been used.

terraform version

+ provider.google v3.17.0
+ provider.google-beta v2.19.0
Request
{
  "availableMemoryMb": 128,
  "description": "My function",
  "entryPoint": "HelloWorld",
  "httpsTrigger": {},
  "ingressSettings": "ALLOW_ALL",
  "name": "xxx/functions/fetch-prometheus-data",
  "runtime": "go111",
  "sourceArchiveUrl": "gs://source-code-prometheus-fetch-v/function_go.zip",
  "timeout": "60s"
 }

Response :
{
"name": "projects/xxx/locations/us-central1/functions/fetch-prometheus-data",
"description": "My function",
"sourceArchiveUrl": "gs://source-code-prometheus-fetch-v/function_go.zip",
"httpsTrigger": {
 "url": "https://xxx/fetch-prometheus-data"
},
"status": "ACTIVE",
"entryPoint": "HelloWorld",
"timeout": "60s",
"availableMemoryMb": 128,
"serviceAccountEmail": "xxxx@appspot.gserviceaccount.com",
"updateTime": "2020-04-20T21:02:42.559Z",
"versionId": "1",
"runtime": "go111",
"ingressSettings": "ALLOW_ALL"
}

If you want to attach your debug log, i will have a look

venkykuberan commented 4 years ago

@preston-hf do you still need help on this issue ? if not i will go head and close it

kmullen-omnislash commented 3 years ago

I've received a similar error when importing a gcloud cli deployed function & trying to change to source_archive_bucket & object

Error while updating cloudfunction configuration: googleapi: Error 400: Invalid value at 'function' (oneof), oneof field 'source_code' is already set. Cannot set 'sourceUploadUrl', invalid