Skip to content

Commit

Permalink
retry added for read authorization policy
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekj3 authored and hkantare committed May 10, 2023
1 parent 9398dcf commit 979095e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ibm/service/iampolicy/resource_ibm_iam_authorization_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ package iampolicy
import (
"fmt"
"log"
"time"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/iampolicymanagementv1"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -411,6 +413,22 @@ func resourceIBMIAMAuthorizationPolicyRead(d *schema.ResourceData, meta interfac
}

authorizationPolicy, resp, err := iampapClient.GetPolicy(getPolicyOptions)

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
authorizationPolicy, resp, err = iampapClient.GetPolicy(getPolicyOptions)
if err != nil || authorizationPolicy == nil {
if resp != nil && resp.StatusCode == 404 {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})

if conns.IsResourceTimeoutError(err) {
authorizationPolicy, resp, err = iampapClient.GetPolicy(getPolicyOptions)
}
if err != nil || resp == nil {
return fmt.Errorf("[ERROR] Error retrieving authorizationPolicy: %s %s", err, resp)
}
Expand Down

0 comments on commit 979095e

Please sign in to comment.