Skip to content

Commit

Permalink
Add delete poll check (#5096) (#9863)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Aug 19, 2021
1 parent e02dbe2 commit 33ae166
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/5096.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pubsub: added polling to `google_pubsub_schema` to deal with eventually consistent deletes
```
42 changes: 41 additions & 1 deletion google/resource_pubsub_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/pubsub_schema.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 33ae166

Please sign in to comment.