Skip to content

Commit 54a2128

Browse files
Retry on Apigee 400 concurrent operation error (#6395) (#4584)
Signed-off-by: Modular Magician <[email protected]>
1 parent 61fd27d commit 54a2128

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.changelog/6395.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
apigee: fixed an issue where `google_apigee_instance` creation would fail due to multiple concurrent instances
3+
```

google-beta/error_retry_predicates.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,14 @@ func isBigTableRetryableError(err error) (bool, string) {
419419

420420
return false, ""
421421
}
422+
423+
// Concurrent Apigee operations can fail with a 400 error
424+
func isApigeeRetryableError(err error) (bool, string) {
425+
if gerr, ok := err.(*googleapi.Error); ok {
426+
if gerr.Code == 400 && strings.Contains(strings.ToLower(gerr.Body), "the resource is locked by another operation") {
427+
return true, "Waiting for other concurrent operations to finish"
428+
}
429+
}
430+
431+
return false, ""
432+
}

google-beta/resource_apigee_instance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func resourceApigeeInstanceCreate(d *schema.ResourceData, meta interface{}) erro
210210
billingProject = bp
211211
}
212212

213-
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate))
213+
res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate), isApigeeRetryableError)
214214
if err != nil {
215215
return fmt.Errorf("Error creating Instance: %s", err)
216216
}
@@ -269,7 +269,7 @@ func resourceApigeeInstanceRead(d *schema.ResourceData, meta interface{}) error
269269
billingProject = bp
270270
}
271271

272-
res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil)
272+
res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil, isApigeeRetryableError)
273273
if err != nil {
274274
return handleNotFoundError(err, d, fmt.Sprintf("ApigeeInstance %q", d.Id()))
275275
}
@@ -337,7 +337,7 @@ func resourceApigeeInstanceDelete(d *schema.ResourceData, meta interface{}) erro
337337
billingProject = bp
338338
}
339339

340-
res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete))
340+
res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete), isApigeeRetryableError)
341341
if err != nil {
342342
return handleNotFoundError(err, d, "Instance")
343343
}

google-beta/resource_apigee_instance_generated_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func testAccCheckApigeeInstanceDestroyProducer(t *testing.T) func(s *terraform.S
675675
billingProject = config.BillingProject
676676
}
677677

678-
_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
678+
_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isApigeeRetryableError)
679679
if err == nil {
680680
return fmt.Errorf("ApigeeInstance still exists at %s", url)
681681
}

0 commit comments

Comments
 (0)