Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_bigtable_instance is incorrectly removed from state #10086

Comments

@ericnorris
Copy link

ericnorris commented Sep 16, 2021

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 the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v0.12.31
+ provider.google (3.81.0)

Affected Resource(s)

  • google_bigtable_instance

Terraform Configuration Files

resource "google_bigtable_instance" "some-instance" {
  name = "some-instance"

  cluster {
    cluster_id   = "some-cluster-c1"
    zone         = "us-central1-c"
    storage_type = "SSD"
  }

}

Debug Output

2021-09-16T14:41:05.659Z [INFO]  plugin.terraform-provider-google_v3.81.0_x5: 2021/09/16 14:41:05 [WARN] Removing some-instance because it's gone: timestamp=2021-09-16T14:41:05.659Z

Panic Output

N/A

Expected Behavior

  • The plan should have failed due to the underlying error.
  • The request & response logs (including the error) should be visible when TF_LOG=trace is set.

Actual Behavior

  • The resource was presumed "gone", and it was planned to be created again:
# google_bigtable_instance.some-instance will be created
  + resource "google_bigtable_instance" "some-instance" {
      + deletion_protection = true
      + display_name        = (known after apply)
      + id                  = (known after apply)
      + instance_type       = "PRODUCTION"
      + name                = "some-instance"
      + project             = (known after apply)

      + cluster {
          + cluster_id   = "some-cluster-c1"
          + kms_key_name = (known after apply)
          + num_nodes    = (known after apply)
          + storage_type = "SSD"
          + zone         = "us-central1-c"
        }
    }
  • There were no request / response logs for the failing API call when TF_LOG=trace was set.

Steps to Reproduce

  1. terraform apply
  2. Do something to cause https://github.com/hashicorp/terraform-provider-google/blob/release-3.81.0/google/resource_bigtable_instance.go#L216 to fail, e.g. disable the bigtable API.
  3. terraform plan

Important Factoids

I spent hours trying to figure this one out.

The underlying cause for us was that the Bigtable client didn't respect the configured user_project_override and billing_project, and was encountering this error:

rpc error: code = PermissionDenied desc = Cloud Bigtable Admin API has not been used in project <project-number> before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/bigtableadmin.googleapis.com/overview?project=<project-number> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

This has been fixed by #10060, which has not yet been incorporated into a release. It was really tough to debug as the request / response logs for these API calls do not appear to be logged by the Bigtable instance client, so it'd be nice if a fix for this issue included ensuring that the Bigtable client is using the HTTP client that is configured to log requests and responses [1].

Ignoring that, I believe that:

if err != nil {
log.Printf("[WARN] Removing %s because it's gone", instanceName)
d.SetId("")
return nil
}

...should be adjusted to only assume the resource is gone on a 404. There is precedent in other resources, e.g:

if isGoogleApiErrorWithCode(err, 403) {
log.Printf("[DEBUG] Got a 403 error trying to read service account key %s, assuming it's gone.", d.Id())
d.SetId("")
return nil

I'd also encourage any other places where this happens to be moved to this pattern where possible.

[1]

client *http.Client

References

@ericnorris ericnorris added the bug label Sep 16, 2021
@ericnorris ericnorris changed the title google_bigtable_instance is removed from state incorrectly google_bigtable_instance is incorrectly removed from state Sep 16, 2021
@rileykarson rileykarson self-assigned this Sep 17, 2021
@kevinsi4508
Copy link
Contributor

I was able to reproduce this. It does seems to be a bug. I will investigate further to see what should be done. Thanks for raising this.

@melinath
Copy link
Collaborator

I think we've had the issue of logging come up before - possibly #12159?

@rileykarson rileykarson removed their assignment Oct 21, 2022
shuyama1 pushed a commit to GoogleCloudPlatform/magic-modules that referenced this issue Nov 7, 2022
modular-magician added a commit to modular-magician/terraform-provider-google-beta that referenced this issue Nov 7, 2022
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Nov 7, 2022
fixes hashicorp#10086

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit to hashicorp/terraform-provider-google-beta that referenced this issue Nov 7, 2022
fixes hashicorp/terraform-provider-google#10086

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit that referenced this issue Nov 7, 2022
fixes #10086

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit to modular-magician/terraform-validator that referenced this issue Nov 7, 2022
fixes hashicorp/terraform-provider-google#10086

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit to GoogleCloudPlatform/terraform-validator that referenced this issue Nov 7, 2022
fixes hashicorp/terraform-provider-google#10086

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
@github-actions
Copy link

github-actions bot commented Dec 8, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.