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

Retry on Apigee 400 concurrent operation error #4584

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/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-beta/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-beta/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-beta/resource_apigee_instance_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,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