-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Data Source: azurerm_system_center_virtual_machine_manager_inventory_items
- normalize the resource ID
#25955
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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,39 +124,67 @@ 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 { | ||||||
if props := item.Properties; props != nil { | ||||||
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) | ||||||
// 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.VirtualMachineTemplateInventoryItem); ok && inventoryType == string(inventoryitems.InventoryTypeVirtualMachineTemplate) { | ||||||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||
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) | ||||||
// 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||
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) | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return results | ||||||
return &results, nil | ||||||
} |
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.
The idea of updating the phrasing of the comment above is so that we don't need to duplicate this multiple times in this function. Please remove these.
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.
Updated