Skip to content

Commit

Permalink
support retry logic on healthcare dataset (hashicorp#4412) (hashicorp…
Browse files Browse the repository at this point in the history
…#8256)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and ScottSuarez committed Jan 21, 2021
1 parent 343395c commit 4cb594c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/4412.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
healthcare: add retry logic on healthcare dataset not initialized error
```
9 changes: 9 additions & 0 deletions google/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,12 @@ func iapClient409Operation(err error) (bool, string) {
}
return false, ""
}

func healthcareDatasetNotInitialized(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 404 && strings.Contains(strings.ToLower(gerr.Body), "dataset not initialized") {
return true, "dataset not initialized - retrying"
}
}
return false, ""
}
8 changes: 4 additions & 4 deletions google/resource_healthcare_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func resourceHealthcareDatasetCreate(d *schema.ResourceData, meta interface{}) e
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate), healthcareDatasetNotInitialized)
if err != nil {
return fmt.Errorf("Error creating Dataset: %s", err)
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func resourceHealthcareDatasetRead(d *schema.ResourceData, meta interface{}) err
billingProject = bp
}

res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil)
res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil, healthcareDatasetNotInitialized)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("HealthcareDataset %q", d.Id()))
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func resourceHealthcareDatasetUpdate(d *schema.ResourceData, meta interface{}) e
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate))
res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate), healthcareDatasetNotInitialized)

if err != nil {
return fmt.Errorf("Error updating Dataset %q: %s", d.Id(), err)
Expand Down Expand Up @@ -276,7 +276,7 @@ func resourceHealthcareDatasetDelete(d *schema.ResourceData, meta interface{}) e
billingProject = bp
}

res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete), healthcareDatasetNotInitialized)
if err != nil {
return handleNotFoundError(err, d, "Dataset")
}
Expand Down
2 changes: 1 addition & 1 deletion google/resource_healthcare_dataset_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func testAccCheckHealthcareDatasetDestroyProducer(t *testing.T) func(s *terrafor
billingProject = config.BillingProject
}

_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, healthcareDatasetNotInitialized)
if err == nil {
return fmt.Errorf("HealthcareDataset still exists at %s", url)
}
Expand Down

0 comments on commit 4cb594c

Please sign in to comment.