Skip to content

Commit ef9c05c

Browse files
committed
Fix vra_catalog_item datasource lookup bug
Signed-off-by: Ferran Rodenas <[email protected]>
1 parent e9a427c commit ef9c05c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

vra/data_source_catalog_item.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,15 @@ func dataSourceCatalogItemRead(d *schema.ResourceData, meta interface{}) error {
129129
return err
130130
}
131131
catalogItems := getResp.GetPayload()
132-
if len(catalogItems.Content) > 1 {
133-
return fmt.Errorf("more than one catalog item found with the same name, try to narrow filter by project_id")
132+
for _, catalogItem := range catalogItems.Content {
133+
if *catalogItem.Name == name {
134+
id = catalogItem.ID.String()
135+
break
136+
}
134137
}
135-
if len(catalogItems.Content) == 0 {
136-
return fmt.Errorf("catalog item %s not found", name)
138+
if id == "" {
139+
return fmt.Errorf("catalog item '%s' not found", name)
137140
}
138-
139-
// GetCatalogItemsUsingGET5 does not return the catalog item schema, so we need to use the GetCatalogItemUsingGET5
140-
// call in order to retrieve it.
141-
id = string(*catalogItems.Content[0].ID)
142141
}
143142

144143
getResp, err := apiClient.CatalogItems.GetCatalogItemUsingGET5(catalog_items.NewGetCatalogItemUsingGET5Params().WithID(strfmt.UUID(id.(string))).WithExpandProjects(withBool(expandProjects)))

0 commit comments

Comments
 (0)