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

Add delete poll check #9863

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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