Skip to content

Commit

Permalink
fix: use standard API for Azure VMs in VMSS with flexible orchestrati…
Browse files Browse the repository at this point in the history
…on mode (#829)
  • Loading branch information
pdecat authored Sep 19, 2024
1 parent 982e49f commit d039004
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 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
6 changes: 6 additions & 0 deletions azure/table_azure_compute_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ func tableAzureComputeVirtualMachineScaleSet(_ context.Context) *plugin.Table {
Type: proto.ColumnType_JSON,
Transform: transform.FromField("VirtualMachineScaleSetProperties.ScaleInPolicy"),
},
{
Name: "orchestration_mode",
Description: "The orchestration mode of the Virtual Machine Scale Set.",
Type: proto.ColumnType_STRING,
Transform: transform.FromGo(),
},
{
Name: "tags_src",
Description: "Resource tags.",
Expand Down
32 changes: 25 additions & 7 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,34 @@ 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
client := compute.NewVirtualMachineScaleSetVMsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer

op, err := client.GetInstanceView(ctx, resourceGroupName, virtualMachine.ScaleSetName, instanceId)
if err != nil {
return nil, err
}
// 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

return op, nil
op, err := client.InstanceView(ctx, resourceGroupName, *virtualMachine.Name)
if err != nil {
plugin.Logger(ctx).Error("Error", "getAzureComputeVirtualMachineScaleSetVmInstanceView", err)
return nil, err
}
return op, nil
} else {
client := compute.NewVirtualMachineScaleSetVMsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer

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
}
}

0 comments on commit d039004

Please sign in to comment.