diff --git a/internal/services/systemcentervirtualmachinemanager/system_center_virtual_machine_manager_inventory_items_data_source.go b/internal/services/systemcentervirtualmachinemanager/system_center_virtual_machine_manager_inventory_items_data_source.go index 020fbe2ed866..742133c1efdd 100644 --- a/internal/services/systemcentervirtualmachinemanager/system_center_virtual_machine_manager_inventory_items_data_source.go +++ b/internal/services/systemcentervirtualmachinemanager/system_center_virtual_machine_manager_inventory_items_data_source.go @@ -107,11 +107,14 @@ func (l SystemCenterVirtualMachineManagerInventoryItemsDataSource) Read() sdk.Re } if model := resp.Model; model != nil { - inventoryItems := flattenInventoryItems(model, state.InventoryType) - if len(inventoryItems) == 0 { + inventoryItems, err := flattenInventoryItems(model, state.InventoryType) + if err != nil { + return err + } + if len(pointer.From(inventoryItems)) == 0 { return fmt.Errorf("no inventory items were found for %s", scvmmServerId) } - state.InventoryItems = inventoryItems + state.InventoryItems = pointer.From(inventoryItems) } metadata.ResourceData.SetId(scvmmServerId.ID()) @@ -121,10 +124,10 @@ func (l SystemCenterVirtualMachineManagerInventoryItemsDataSource) Read() sdk.Re } } -func flattenInventoryItems(input *[]inventoryitems.InventoryItem, inventoryType string) []InventoryItem { +func flattenInventoryItems(input *[]inventoryitems.InventoryItem, inventoryType string) (*[]InventoryItem, error) { results := make([]InventoryItem, 0) if input == nil { - return results + return &results, nil } for _, item := range *input { @@ -132,22 +135,44 @@ func flattenInventoryItems(input *[]inventoryitems.InventoryItem, inventoryType inventoryItem := InventoryItem{} if v, ok := props.(inventoryitems.CloudInventoryItem); ok && inventoryType == string(inventoryitems.InventoryTypeCloud) { - inventoryItem.id = pointer.From(item.Id) + // Service API indicates that the static segment `inventoryItems` in the resource ID of the Inventory Item should start with lowercase. See more details from https://github.com/Azure/azure-rest-api-specs/blob/92c409d93f895a30d51603b2fda78a49b3a2cd60/specification/scvmm/resource-manager/Microsoft.ScVmm/stable/2023-10-07/scvmm.json#L1785 + // But the static segment `InventoryItems` in the resource ID of the Inventory Item returned by the API starts with uppercase. So all instances of setting the inventory item ID must use ParseInventoryItemIDInsensitively() in Read() to normalize the resource ID + scvmmServerInventoryItemId, err := inventoryitems.ParseInventoryItemIDInsensitively(pointer.From(item.Id)) + if err != nil { + return nil, err + } + inventoryItem.id = scvmmServerInventoryItemId.ID() + inventoryItem.name = pointer.From(v.InventoryItemName) inventoryItem.Uuid = pointer.From(v.Uuid) results = append(results, inventoryItem) } else if v, ok := props.(inventoryitems.VirtualMachineInventoryItem); ok && inventoryType == string(inventoryitems.InventoryTypeVirtualMachine) { - inventoryItem.id = pointer.From(item.Id) + scvmmServerInventoryItemId, err := inventoryitems.ParseInventoryItemIDInsensitively(pointer.From(item.Id)) + if err != nil { + return nil, err + } + inventoryItem.id = scvmmServerInventoryItemId.ID() + inventoryItem.name = pointer.From(v.InventoryItemName) inventoryItem.Uuid = pointer.From(v.Uuid) results = append(results, inventoryItem) } else if v, ok := props.(inventoryitems.VirtualMachineTemplateInventoryItem); ok && inventoryType == string(inventoryitems.InventoryTypeVirtualMachineTemplate) { - inventoryItem.id = pointer.From(item.Id) + scvmmServerInventoryItemId, err := inventoryitems.ParseInventoryItemIDInsensitively(pointer.From(item.Id)) + if err != nil { + return nil, err + } + inventoryItem.id = scvmmServerInventoryItemId.ID() + inventoryItem.name = pointer.From(v.InventoryItemName) inventoryItem.Uuid = pointer.From(v.Uuid) results = append(results, inventoryItem) } else if v, ok := props.(inventoryitems.VirtualNetworkInventoryItem); ok && inventoryType == string(inventoryitems.InventoryTypeVirtualNetwork) { - inventoryItem.id = pointer.From(item.Id) + scvmmServerInventoryItemId, err := inventoryitems.ParseInventoryItemIDInsensitively(pointer.From(item.Id)) + if err != nil { + return nil, err + } + inventoryItem.id = scvmmServerInventoryItemId.ID() + inventoryItem.name = pointer.From(v.InventoryItemName) inventoryItem.Uuid = pointer.From(v.Uuid) results = append(results, inventoryItem) @@ -155,5 +180,5 @@ func flattenInventoryItems(input *[]inventoryitems.InventoryItem, inventoryType } } - return results + return &results, nil }