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

fix(iam-access-groups): added retry logic for access groups read #4098

Merged
merged 1 commit into from
Oct 18, 2022
Merged
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
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