Skip to content

Commit

Permalink
Retry on Apigee 400 concurrent operation error (#6395) (#12289)
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 committed Aug 9, 2022
1 parent 69e2aa2 commit 7efe9d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/6395.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
apigee: fixed an issue where `google_apigee_instance` creation would fail due to multiple concurrent instances
```
11 changes: 11 additions & 0 deletions google/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,14 @@ func isBigTableRetryableError(err error) (bool, string) {

return false, ""
}

// Concurrent Apigee operations can fail with a 400 error
func isApigeeRetryableError(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 400 && strings.Contains(strings.ToLower(gerr.Body), "the resource is locked by another operation") {
return true, "Waiting for other concurrent operations to finish"
}
}

return false, ""
}
6 changes: 3 additions & 3 deletions google/resource_apigee_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func resourceApigeeInstanceCreate(d *schema.ResourceData, meta interface{}) erro
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), isApigeeRetryableError)
if err != nil {
return fmt.Errorf("Error creating Instance: %s", err)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func resourceApigeeInstanceRead(d *schema.ResourceData, meta interface{}) error
billingProject = bp
}

res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil)
res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil, isApigeeRetryableError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("ApigeeInstance %q", d.Id()))
}
Expand Down Expand Up @@ -337,7 +337,7 @@ func resourceApigeeInstanceDelete(d *schema.ResourceData, meta interface{}) erro
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), isApigeeRetryableError)
if err != nil {
return handleNotFoundError(err, d, "Instance")
}
Expand Down
2 changes: 1 addition & 1 deletion google/resource_apigee_instance_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func testAccCheckApigeeInstanceDestroyProducer(t *testing.T) func(s *terraform.S
billingProject = config.BillingProject
}

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

0 comments on commit 7efe9d3

Please sign in to comment.