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.36k stars 1.75k forks source link

Intermittent failures enabling bigquery via `google_project_service` #11465

Open davidstanke opened 2 years ago

davidstanke commented 2 years ago

Community Note

Terraform Version

1.0.7

Affected Resource(s)

google_project_service

Terraform Configuration Files

resource "google_project_service" "bq_api" {
  service                    = "bigquery.googleapis.com"
  disable_dependent_services = true
}

resource "google_bigquery_dataset" "four_keys" {
  dataset_id = "four_keys"
  location   = var.bigquery_region
  depends_on = [
    google_project_service.bq_api
  ]
}

Debug Output

https://gist.github.com/davidstanke/fb11edc13437a1b06f4f575cae7d6418

Expected Behavior

The dataset resource has an explicit dependency on the BiqQuery API resource, so the api should be enabled before TF attempts to create the dataset

Actual Behavior

TF was unable to create the dataset, because the API wasn't enabled. We have observed this behavior from time to time but not always. It's flaky! It appears that BQ sometimes returns a success status prior to being actually usable(?)

b/374161376

melinath commented 2 years ago

Are you able to confirm from the debug output that the google_project_service resource completes before the google_bigquery_dataset is attempted? If so, this is likely a race condition on the API side - see https://github.com/hashicorp/terraform-provider-google/issues/8938 for more details.

davidstanke commented 2 years ago

Hi @melinath, yes, we can confirm that Terraform reports that the google_project_service is complete before attempting to add the dataset, or to query it. So it appears that this is an API issue -- the API is reporting completion before it's actually ready to interact. How do we get this fixed?

rileykarson commented 2 years ago

Not a direct answer to your question about fixing it, but for additional Google-internal context also see b/228371710

melinath commented 2 years ago

@davidstanke one possible workaround would be to add a delay to your terraform plan.

davidstanke commented 2 years ago

Thanks @rileykarson and @melinath -- I've added a note to that internal bug and eagerly await a solution. Meanwhile, yeah: adding a delay may be the best option, though it makes me sad.