-
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 2 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 pointer.To(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 API starts with uppercase. So it has to 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. Can we update this description to explain that all instances of this will use the case insensitive parser, then we don't need to repeat this comment multiple times
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.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 API starts with uppercase. So it has to 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.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 API starts with uppercase. So it has to 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 API starts with uppercase. So it has to 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 pointer.To(results), nil | ||||||
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 |
||||||
} |
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.
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