Skip to content

Commit

Permalink
fix(iam-access-groups): added retry logic for access groups read
Browse files Browse the repository at this point in the history
  • Loading branch information
Narinder committed Oct 10, 2022
1 parent 195b924 commit 04fb27f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions ibm/service/iamaccessgroup/resource_ibm_iam_access_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package iamaccessgroup
import (
"context"
"fmt"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/iamaccessgroupsv2"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"time"
)

func ResourceIBMIAMAccessGroup() *schema.Resource {
Expand Down Expand Up @@ -82,12 +85,23 @@ func resourceIBMIAMAccessGroupRead(context context.Context, d *schema.ResourceDa
}
agrpID := d.Id()
getAccessGroupOptions := iamAccessGroupsClient.NewGetAccessGroupOptions(agrpID)
agrp, detailedResponse, err := iamAccessGroupsClient.GetAccessGroup(getAccessGroupOptions)
if err != nil || agrp == nil {
if detailedResponse != nil && detailedResponse.StatusCode == 404 {
d.SetId("")
return nil
var agrp *iamaccessgroupsv2.Group
var detailedResponse *core.DetailedResponse
err = resource.RetryContext(context, 5*time.Second, func() *resource.RetryError {
agrp, detailedResponse, err = iamAccessGroupsClient.GetAccessGroup(getAccessGroupOptions)
if err != nil || agrp == nil {
if detailedResponse != nil && detailedResponse.StatusCode == 404 {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})

if conns.IsResourceTimeoutError(err) {
agrp, detailedResponse, err = iamAccessGroupsClient.GetAccessGroup(getAccessGroupOptions)
}
if err != nil || agrp == nil || detailedResponse == nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error retrieving access group: %s. API Response: %s", err, detailedResponse))
}
version := detailedResponse.GetHeaders().Get("etag")
Expand Down

0 comments on commit 04fb27f

Please sign in to comment.