Skip to content

Commit

Permalink
Retry reads of organization datasource (#2878)
Browse files Browse the repository at this point in the history
Merged PR #2878.
  • Loading branch information
rileykarson authored and modular-magician committed Dec 20, 2019
1 parent 467a6f0 commit dcc8300
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,32 @@ func dataSourceOrganizationRead(d *schema.ResourceData, meta interface{}) error
var organization *cloudresourcemanager.Organization
if v, ok := d.GetOk("domain"); ok {
filter := fmt.Sprintf("domain=%s", v.(string))
resp, err := config.clientResourceManager.Organizations.Search(&cloudresourcemanager.SearchOrganizationsRequest{
Filter: filter,
}).Do()
var resp *cloudresourcemanager.SearchOrganizationsResponse
err := retryTimeDuration(func() (err error) {
resp, err = config.clientResourceManager.Organizations.Search(&cloudresourcemanager.SearchOrganizationsRequest{
Filter: filter,
}).Do()
return err
}, d.Timeout(schema.TimeoutRead))
if err != nil {
return fmt.Errorf("Error reading organization: %s", err)
}

if len(resp.Organizations) == 0 {
return fmt.Errorf("Organization not found: %s", v)
}

if len(resp.Organizations) > 1 {
return fmt.Errorf("More than one matching organization found")
}

organization = resp.Organizations[0]
} else if v, ok := d.GetOk("organization"); ok {
resp, err := config.clientResourceManager.Organizations.Get(canonicalOrganizationName(v.(string))).Do()
var resp *cloudresourcemanager.Organization
err := retryTimeDuration(func() (err error) {
resp, err = config.clientResourceManager.Organizations.Get(canonicalOrganizationName(v.(string))).Do()
return err
}, d.Timeout(schema.TimeoutRead))
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("Organization Not Found : %s", v))
}
Expand Down

0 comments on commit dcc8300

Please sign in to comment.