Skip to content

Commit

Permalink
support retry logic on healthcare dataset (#4412) (#2885)
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 Jan 20, 2021
1 parent 516fb2d commit 5c4b829
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 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-beta/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, ""
}
2 changes: 1 addition & 1 deletion google-beta/resource_dataflow_flex_template_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"google.golang.org/api/compute/v1"
compute "google.golang.org/api/compute/v1"
)

func TestAccDataflowFlexTemplateJob_basic(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions google-beta/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-beta/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 5c4b829

Please sign in to comment.