Skip to content

Commit

Permalink
fix: add VMSS details to standard VM table for flexible orchestration…
Browse files Browse the repository at this point in the history
… mode
  • Loading branch information
pdecat committed Aug 29, 2024
1 parent 6cbb647 commit c69ade6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions azure/table_azure_compute_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func tableAzureComputeVirtualMachine(_ context.Context) *plugin.Table {
Description: "The friendly name that identifies the virtual machine.",
Type: proto.ColumnType_STRING,
},
{
Name: "virtual_machine_scale_set",
Description: "Scale set details for virtual machines managed in flexible orchestration mode.",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("VirtualMachineProperties.VirtualMachineScaleSet"),
},
{
Name: "power_state",
Description: "Specifies the power state of the VM.",
Expand Down
7 changes: 7 additions & 0 deletions azure/table_azure_compute_virtual_machine_scale_set_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,22 @@ func getAzureComputeVirtualMachineScaleSetVmInstanceView(ctx context.Context, d

session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
plugin.Logger(ctx).Error("Error", "getAzureComputeVirtualMachineScaleSetVmInstanceView", err)
return nil, err
}
subscriptionID := session.SubscriptionID

// When VMs are managed by scale sets in flexible orchestration mode,
// standard Azure VM APIs must be must be used.
// See https://learn.microsoft.com/en-us/answers/questions/1418158/rest-api-request-returns-badrequest-for-vmss
// and https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-orchestration-modes?WT.mc_id=modinfra-31635-pierrer#what-has-changed-with-flexible-orchestration-mode
if h.ParentItem.(compute.VirtualMachineScaleSet).OrchestrationMode == compute.Flexible {
client := compute.NewVirtualMachinesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer

op, err := client.InstanceView(ctx, resourceGroupName, *virtualMachine.Name)
if err != nil {
plugin.Logger(ctx).Error("Error", "getAzureComputeVirtualMachineScaleSetVmInstanceView", err)
return nil, err
}
return op, nil
Expand All @@ -344,6 +350,7 @@ func getAzureComputeVirtualMachineScaleSetVmInstanceView(ctx context.Context, d

op, err := client.GetInstanceView(ctx, resourceGroupName, virtualMachine.ScaleSetName, instanceId)
if err != nil {
plugin.Logger(ctx).Error("Error", "getAzureComputeVirtualMachineScaleSetVmInstanceView", err)
return nil, err
}
return op, nil
Expand Down

0 comments on commit c69ade6

Please sign in to comment.