Skip to content
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

Attach and Detach disk to Virtual Machine in a Scale Set API is broken #22773

Closed
andreacappelletti97 opened this issue Apr 22, 2024 · 4 comments
Assignees
Labels
Compute customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.

Comments

@andreacappelletti97
Copy link

Bug Report

  • github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5

  • SDK version: v5.6.0

  • go version go1.22.1 darwin/arm64

  • What happened?
    I'm trying to attach and detach a disk to a virtual machine in a virtual machine scale set using this SDK, but I'm getting the following error:

The subscription is not enabled for using the attach detach data disks API.
  • What did you expect or want to happen?
    I would like to be able to attach a disk to my virtual machine in the scale set.

  • How can we reproduce it?

package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
	"log"
	"os"
	"time"
)

func ptr[T any](v T) *T {
	return &v
}

func main() {
	fmt.Println("Hello, world!")

	var subscriptionId = "myId"
	var deploymentName = "deployment-example"
	var resourceGroupName = "example-rg"
	var diskName = "disk-demo"
	
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		log.Fatalf("failed to obtain a credential: %v", err)
	}
	ctx := context.TODO()

	clientFactory, err := armcompute.NewClientFactory(subscriptionId, cred, nil)
	if err != nil {
		log.Fatalf("failed to create client: %v", err)
	}

	pager := clientFactory.NewVirtualMachineScaleSetVMsClient().NewListPager(
		resourceGroupName,
		deploymentName,
		&armcompute.VirtualMachineScaleSetVMsClientListOptions{
			Filter: nil,
			Select: nil,
			Expand: nil,
		})
	for pager.More() {
		page, err := pager.NextPage(ctx)
		if err != nil {
			log.Fatalf("failed to advance page: %v", err)
		}
		for _, v := range page.Value {
			_ = v
			fmt.Printf("VMSS ID: %s\n", *v.ID)
			fmt.Printf("VMSS instance ID: %s\n", *v.InstanceID)
			fmt.Printf("VMSS instance name: %s\n", *v.Name)
			fmt.Printf("VM id %s\n", *v.Properties.VMID)

		}

	}

	diskSpec := armcompute.Disk{
		Location: ptr("eastus2"),
		SKU: &armcompute.DiskSKU{
			Name: (*armcompute.DiskStorageAccountTypes)(ptr("Premium_LRS")),
			Tier: ptr("Standard"),
		},
		Properties: &armcompute.DiskProperties{
			CreationData: &armcompute.CreationData{
				CreateOption: ptr(armcompute.DiskCreateOptionEmpty),
			},
			DiskIOPSReadWrite: ptr(int64(4000)),
			DiskSizeGB:        ptr(int32(16)),
		},
	}
	diskOptions := armcompute.DisksClientBeginCreateOrUpdateOptions{}

	// Initiating disk creation
	diskResponse, err := clientFactory.NewDisksClient().BeginCreateOrUpdate(ctx, resourceGroupName, diskName, diskSpec, &diskOptions)
	if err != nil {
		fmt.Printf("err %v", err)
		os.Exit(0)
	}

	// Wait for the disk to be created
	disk, err := diskResponse.PollUntilDone(ctx,
		&runtime.PollUntilDoneOptions{Frequency: 15 * time.Second},
	)

	if err != nil {
		fmt.Printf("err %v", err)
		os.Exit(0)
	}

	if disk.Properties == nil && disk.Properties.ProvisioningState == nil {
		fmt.Printf("err %v", err)
		os.Exit(0)
	}

	state := *disk.Properties.ProvisioningState
	if state != "Succeeded" {
		fmt.Printf("err %v", err)
		os.Exit(0)
	}

	// Attach the disk to the VMSS instance
	poller, err := clientFactory.NewVirtualMachineScaleSetVMsClient().BeginAttachDetachDataDisks(
		ctx,
		resourceGroupName,
		deploymentName,
		"0",
		armcompute.AttachDetachDataDisksRequest{
			DataDisksToAttach: []*armcompute.DataDisksToAttach{
				{
					DiskID: disk.ID,
					Lun:    ptr(int32(0)),
				},
			},
		}, nil,
	)
	if err != nil {
		fmt.Printf("err %v", err)
		os.Exit(0)
	}

	// Wait for the disk to be attached
	res, err := poller.PollUntilDone(ctx, nil)
	if err != nil {
		fmt.Printf("err %v", err)
		os.Exit(0)
	}

	if res.DataDisks == nil {
		fmt.Printf("err %v", err)
		os.Exit(0)
	}

}
  • Anything we should know about your environment.
    I have owner permissions in my subscription, additionally I have added the following permissions
permissions {
    actions = [
      # write permissions
      "Microsoft.Authorization/roleAssignments/write",
      "Microsoft.Resources/deploymentStacks/write",
      "Microsoft.Resources/deployments/write",
      "Microsoft.Compute/virtualMachineScaleSets/write",
      "Microsoft.Compute/virtualMachineScaleSets/virtualMachines/write",
      "Microsoft.Network/virtualNetworks/subnets/write",
      "Microsoft.Network/publicIPAddresses/write",
      "Microsoft.Network/natGateways/write",
      "Microsoft.Network/networkSecurityGroups/write",
      "Microsoft.ManagedIdentity/userAssignedIdentities/write",
      "Microsoft.ManagedIdentity/userAssignedIdentities/assign/action",
      "Microsoft.ManagedIdentity/userAssignedIdentities/delete",
      "Microsoft.Compute/disks/write",
      "Microsoft.Insights/autoscaleSettings/write",
      # read permissions
      "Microsoft.Resources/subscriptions/resourcegroups/read",
      "Microsoft.Compute/images/read",
      "Microsoft.Compute/virtualMachineScaleSets/read",
      "Microsoft.Compute/virtualMachineScaleSets/virtualMachines/read",
      "Microsoft.Compute/virtualMachineScaleSets/virtualMachines/extensions/read",
      "Microsoft.Resources/deploymentStacks/read",
      "Microsoft.Resources/deployments/read",
      "Microsoft.Network/virtualNetworks/read",
      "Microsoft.Network/virtualNetworks/subnets/read",
      "Microsoft.Network/publicIPAddresses/read",
      "Microsoft.Network/natGateways/read",
      "Microsoft.Network/networkSecurityGroups/read",
      "Microsoft.Compute/disks/read",
      "Microsoft.Insights/autoscaleSettings/read",
      # delete permissions
      "Microsoft.Authorization/roleAssignments/delete",
      "Microsoft.Resources/deploymentStacks/delete",
      "Microsoft.Resources/deployments/delete",
      "Microsoft.Compute/virtualMachineScaleSets/delete",
      "Microsoft.Compute/virtualMachineScaleSets/virtualMachines/delete",
      "Microsoft.Network/publicIPAddresses/delete",
      "Microsoft.Network/natGateways/delete",
      "Microsoft.Network/networkSecurityGroups/delete",
      "Microsoft.Network/virtualNetworks/subnets/delete",
      "Microsoft.Compute/disks/delete",
      "Microsoft.Insights/autoscaleSettings/delete",
      # network permissions
      "Microsoft.Network/virtualNetworks/subnets/join/action",
      "Microsoft.Network/natGateways/join/action",
      "Microsoft.Network/networkSecurityGroups/join/action",
      # dns read permission
      "Microsoft.Network/dnsZones/read",
      "Microsoft.Network/dnsZones/TXT/read",
      "Microsoft.Network/dnsZones/TXT/write",
      "Microsoft.Compute/virtualMachineScaleSets/virtualMachines/*"
    ]

I'm getting the same issue from the online runner:
Screenshot 2024-04-09 at 02 26 53

Ref: https://learn.microsoft.com/en-us/answers/questions/1643764/when-trying-to-use-beginattachdetachdatadisks(usin

@github-actions github-actions bot added Compute customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team. labels Apr 22, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @amjads1 @avirishuv @Drewm3 @Vaibhav-Agar.

@hilaryw29
Copy link

Hi @andreacappelletti97, we're taking a look at this. Thanks!

@andreacappelletti97
Copy link
Author

Hi @hilaryw29 , any updates on this issue?

@andreacappelletti97
Copy link
Author

Solution

In order to use that specific API you will have to follow these steps to enable it in your subscription:

Prerequisites

To register feature you need Contributor or Owner role on subscription.

You can register this feature from CLI, first login:

az login

Then select your subscription:
az account set --subscription "xxxxxx" ->Please replace xxxx by your Sub. ID

Then enable the API for your subscription:

az feature registration create --namespace Microsoft.Compute --name UseNewDataDisksAttachDetachApi

Additionally, you also need to enable a feature called EtagPreview:

az feature registration show --name EtagPreview --provider-namespace Microsoft.Compute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compute customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants