-
Notifications
You must be signed in to change notification settings - Fork 88
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
DXCDT-364: Add organization data source #475
Conversation
e07db05
to
b27042e
Compare
b27042e
to
926ca21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally a good contribution but just two questions about performance regarding lookup by name and fetching all organization members.
outerLoop: | ||
for { | ||
organizations, err := api.Organization.List(management.Page(page)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
for _, organization := range organizations.Organizations { | ||
if organization.GetName() == name { | ||
foundOrganization = organization | ||
break outerLoop | ||
} | ||
} | ||
|
||
if !organizations.HasNext() { | ||
break | ||
} | ||
|
||
page++ | ||
} | ||
|
||
if foundOrganization == nil { | ||
return diag.Errorf("No organization found with \"name\" = %q", name) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it is ok to provide the ability to lookup by name. But given that some tenants have thousands of organizations, might we suggest to the end user to lookup by ID for most performant results? I can just see this loop taking a very long time and users not understanding why.
foundConnections, err := fetchAllOrganizationConnections(api, foundOrganization.GetID()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
result = multierror.Append( | ||
result, | ||
data.Set("connections", flattenOrganizationConnections(foundConnections)), | ||
) | ||
|
||
foundMembers, err := fetchAllOrganizationMembers(api, foundOrganization.GetID()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
result = multierror.Append( | ||
result, | ||
data.Set("members", flattenOrganizationMembers(foundMembers)), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any performance concerns about retrieving all connections and members? Connections should be a reasonable quality but it is possible for an organization to possess a large number of members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there's a limit on the API, they only return 1000 items at most.
Add docs
926ca21
to
7fc205c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm 👍
return diag.FromErr(err) | ||
} | ||
} else { | ||
name := data.Get("name").(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to offer looking up the org by name, besides just by ID? Just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily, we could consider removing it and allowing only lookup based on ID. But then it would be best to remove the functionality from all other data sources as well as there was a precedent set through the client data source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this won't apply to all resources (only those that have unique names). Whereas in others it makes sense. If possible, consider having this for those resources only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep indeed, for the resource server data source I'm using the identifier instead of the name, as that is not unique for those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that if it turns out that customers actually need this functionality in other resources, it can always be added later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You raise a good point, I'll have to investigate the topic a bit deeper. For now I'll keep this as is in the PR however before we cut a release with all the data sources added we'll take a decision whether to only allow id's for the lookup or id's and names.
return diag.FromErr(result.ErrorOrNil()) | ||
} | ||
|
||
func fetchAllOrganizationConnections(api *management.Management, organizationID string) ([]*management.OrganizationConnection, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we can consider using a generic helper for the paging logic, which seems to be repeated in a number of places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO a better place for this would be the Go SDK itself. It would be nice if it would provide functions like "ListAll()" to wrap that logic. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good idea!
🔧 Changes
Adding support for organization data sources in this PR. They'll be available by quering based on
organization_id
orname
. The data source will also additionally include connections compared to the organization resource.📚 References
🔬 Testing
📝 Checklist