From e4564a5ded9cb221ca4c7115d9ec8f38f425b024 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 19 Aug 2021 20:43:39 +0000 Subject: [PATCH] Add delete poll check (#5096) Signed-off-by: Modular Magician --- .changelog/5096.txt | 3 ++ google/resource_pubsub_schema.go | 42 +++++++++++++++++++++- website/docs/r/pubsub_schema.html.markdown | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .changelog/5096.txt diff --git a/.changelog/5096.txt b/.changelog/5096.txt new file mode 100644 index 00000000000..ee0e4b5d7d0 --- /dev/null +++ b/.changelog/5096.txt @@ -0,0 +1,3 @@ +```release-note:bug +pubsub: added polling to `google_pubsub_schema` to deal with eventually consistent deletes +``` diff --git a/google/resource_pubsub_schema.go b/google/resource_pubsub_schema.go index 4b886390e73..60a70184a72 100644 --- a/google/resource_pubsub_schema.go +++ b/google/resource_pubsub_schema.go @@ -38,7 +38,7 @@ func resourcePubsubSchema() *schema.Resource { Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(4 * time.Minute), Update: schema.DefaultTimeout(4 * time.Minute), - Delete: schema.DefaultTimeout(4 * time.Minute), + Delete: schema.DefaultTimeout(6 * time.Minute), }, Schema: map[string]*schema.Schema{ @@ -137,6 +137,41 @@ func resourcePubsubSchemaCreate(d *schema.ResourceData, meta interface{}) error return resourcePubsubSchemaRead(d, meta) } +func resourcePubsubSchemaPollRead(d *schema.ResourceData, meta interface{}) PollReadFunc { + return func() (map[string]interface{}, error) { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{PubsubBasePath}}projects/{{project}}/schemas/{{name}}") + if err != nil { + return nil, err + } + + billingProject := "" + + project, err := getProject(d, config) + if err != nil { + return nil, fmt.Errorf("Error fetching project for Schema: %s", err) + } + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return nil, err + } + + res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil) + if err != nil { + return res, err + } + return res, nil + } +} + func resourcePubsubSchemaRead(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) userAgent, err := generateUserAgentString(d, config.userAgent) @@ -272,6 +307,11 @@ func resourcePubsubSchemaDelete(d *schema.ResourceData, meta interface{}) error return handleNotFoundError(err, d, "Schema") } + err = PollingWaitTime(resourcePubsubSchemaPollRead(d, meta), PollCheckForAbsence, "Deleting Schema", d.Timeout(schema.TimeoutCreate), 10) + if err != nil { + return fmt.Errorf("Error waiting to delete Schema: %s", err) + } + log.Printf("[DEBUG] Finished deleting Schema %q: %#v", d.Id(), res) return nil } diff --git a/website/docs/r/pubsub_schema.html.markdown b/website/docs/r/pubsub_schema.html.markdown index de302298c96..3096333625e 100644 --- a/website/docs/r/pubsub_schema.html.markdown +++ b/website/docs/r/pubsub_schema.html.markdown @@ -92,7 +92,7 @@ This resource provides the following - `create` - Default is 4 minutes. - `update` - Default is 4 minutes. -- `delete` - Default is 4 minutes. +- `delete` - Default is 6 minutes. ## Import