Skip to content

Commit 0de6f63

Browse files
committed
fix retry for identity tag
1 parent 70ac0ce commit 0de6f63

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

oci/identity_tag_resource.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func (s *IdentityTagResourceCrud) Delete() error {
447447
func IdentityTaggingWaitForWorkRequest(workRequestId *string, entityType string, action oci_identity.WorkRequestResourceActionTypeEnum,
448448
timeout time.Duration, disableFoundRetries bool, client *oci_identity.IdentityClient) (*string, error) {
449449
retryPolicy := GetRetryPolicy(disableFoundRetries, "identity")
450-
retryPolicy.ShouldRetryOperation = analyticsInstanceWorkRequestShouldRetryFunc(timeout)
450+
retryPolicy.ShouldRetryOperation = identityTagWorkRequestShouldRetryFunc(timeout)
451451
response := oci_identity.GetTaggingWorkRequestResponse{}
452452
stateConf := &resource.StateChangeConf{
453453
Pending: []string{
@@ -635,3 +635,26 @@ func getIdentityTagCompositeId(tagName string, tagNamespaceId string) string {
635635
compositeId := "tagNamespaces/" + tagNamespaceId + "/tags/" + tagName
636636
return compositeId
637637
}
638+
639+
func identityTagWorkRequestShouldRetryFunc(timeout time.Duration) func(response oci_common.OCIOperationResponse) bool {
640+
startTime := time.Now()
641+
stopTime := startTime.Add(timeout)
642+
return func(response oci_common.OCIOperationResponse) bool {
643+
644+
// Stop after timeout has elapsed
645+
if time.Now().After(stopTime) {
646+
return false
647+
}
648+
649+
// Make sure we stop on default rules
650+
if shouldRetry(response, false, "identity", startTime) {
651+
return true
652+
}
653+
654+
// Only stop if the time Finished is set
655+
if workRequestResponse, ok := response.Response.(oci_identity.GetWorkRequestResponse); ok {
656+
return workRequestResponse.TimeFinished == nil
657+
}
658+
return false
659+
}
660+
}

oci/identity_tag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestIdentityTagResource_basic(t *testing.T) {
101101
SaveConfigContent(config+compartmentIdVariableStr+TagResourceDependencies+
102102
GenerateResourceFromRepresentationMap("oci_identity_tag", "test_tag", Optional, Create, tagRepresentation), "identity", "tag", t)
103103

104-
ResourceTest(t, testAccCheckIdentityTagDestroy, []resource.TestStep{
104+
ResourceTest(t, nil, []resource.TestStep{
105105
// verify Create
106106
{
107107
Config: config + compartmentIdVariableStr + TagResourceDependencies +

0 commit comments

Comments
 (0)