Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

[Issue-103]Unneccesary lookup of BusinessGroupId via Identity API #105

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions sdk/vra7_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ func (c *APIClient) GetBusinessGroupID(businessGroupName string, tenant string)
if unmarshallErr != nil {
return "", unmarshallErr
}

if len(businessGroups.Content) == 0 {
path = path + "/membership"

membershipURL := c.BuildEncodedURL(path, nil)

resp, respErr := c.Get(membershipURL, nil)
if respErr != nil {
return "", respErr
}
unmarshallErr := utils.UnmarshalJSON(resp.Body, &businessGroups)
if unmarshallErr != nil {
return "", unmarshallErr
}
}

// BusinessGroups array will contain only one BusinessGroup element containing the BG
// with the name businessGroupName.
// Fetch the id of that
Expand Down
4 changes: 2 additions & 2 deletions vra7/resource_vra7_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func readProviderConfiguration(d *schema.ResourceData, vraClient *sdk.APIClient)
}

// if catalog item name is provided, fetch the catalog item id
if len(providerSchema.CatalogItemName) > 0 {
if len(providerSchema.CatalogItemID) == 0 && len(providerSchema.CatalogItemName) > 0 {
id, err := vraClient.ReadCatalogItemByName(providerSchema.CatalogItemName)
if err != nil {
return &providerSchema, err
Expand All @@ -634,7 +634,7 @@ func readProviderConfiguration(d *schema.ResourceData, vraClient *sdk.APIClient)
}

// get the business group id from name
if len(providerSchema.BusinessGroupName) > 0 {
if len(providerSchema.BusinessGroupID) == 0 && len(providerSchema.BusinessGroupName) > 0 {
id, err := vraClient.GetBusinessGroupID(providerSchema.BusinessGroupName, vraClient.Tenant)
if err != nil {
return &providerSchema, err
Expand Down