Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.64k stars 843 forks source link

Invalid polling URL when creating resources #21035

Closed MathKlim closed 10 months ago

MathKlim commented 1 year ago

Bug Report

"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
go 1.20

require (
    github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1
    github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0
    github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.1.1
    github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1
)

go version go1.20.4 linux/amd64

I'm trying to use the go sdk to create generic resources. Here I am trying to create a resource group and a user assigned managed identity.

package main

import (
    "context"
    "log"
    "os"

    "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
    "github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
)

var subscriptionID string

var resourcesClientFactory *armresources.ClientFactory

var (
    resourceGroupClient *armresources.ResourceGroupsClient
    resourcesClient     *armresources.Client
)

type ResourceGroup struct {
    Name     string
    Location string
}

type AzResource struct {
    ResourceGroupName         string
    ResourceProviderNamespace string
    ResourceType              string
    ResourceName              string
    ResourceLocation          string
    ApiVersion                string
}

var resource_group = ResourceGroup{
    Name:     "rg-test-daa-euw-dev",
    Location: "westeurope",
}

var managed_id = AzResource{
    ResourceGroupName:         resource_group.Name,
    ResourceProviderNamespace: "Microsoft.ManagedIdentity",
    ResourceType:              "userAssignedIdentities",
    ResourceName:              "mid-test-daa-euw-dev",
    ResourceLocation:          resource_group.Location,
    ApiVersion:                "2023-01-31",
}

func main() {
    subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID")
    if len(subscriptionID) == 0 {
        log.Fatal("AZURE_SUBSCRIPTION_ID is not set.")
    }

    cred, err := azidentity.NewDefaultAzureCredential(nil)
    if err != nil {
        log.Fatal(err)
    }
    ctx := context.Background()

    resourcesClientFactory, err = armresources.NewClientFactory(subscriptionID, cred, nil)
    if err != nil {
        log.Fatal(err)
    }
    resourceGroupClient = resourcesClientFactory.NewResourceGroupsClient()

    resourcesClient = resourcesClientFactory.NewClient()

    resourceGroup, err := createResourceGroup(ctx, resource_group)
    if err != nil {
        log.Fatal(err)
    }
    log.Println("resources group:", *resourceGroup.ID)

    boolResp, err := resourcesClient.CheckExistence(
        ctx,
        managed_id.ResourceGroupName,
        managed_id.ResourceProviderNamespace,
        "",
        managed_id.ResourceType,
        managed_id.ResourceName,
        managed_id.ApiVersion,
        nil)
    if err != nil {
        log.Fatal(err)
    }
    log.Println("resources does exists:", boolResp.Success)

    createPoller, err := resourcesClient.BeginCreateOrUpdate(
        ctx,
        managed_id.ResourceGroupName,
        managed_id.ResourceProviderNamespace,
        "",
        managed_id.ResourceType,
        managed_id.ResourceName,
        managed_id.ApiVersion,
        armresources.GenericResource{
            Location: to.Ptr(managed_id.ResourceLocation),
        },
        nil)
    if err != nil {
        log.Fatal(err)
    }

    pollOptions := runtime.PollUntilDoneOptions{
        Frequency: 0, // Pass zero to accept the default value (30s).
    }
    res, err := createPoller.PollUntilDone(ctx, &pollOptions)
    if err != nil {
        log.Fatal(err)
    }
    log.Println("created resources:", res.ID)
}

Instead of getting of log like created resources: with the Id of my user assigned identity, of get the following one.

2023/06/19 22:49:42 resources group: /subscriptions/REDACTED/resourceGroups/rg-test-daa-euw-dev
2023/06/19 22:49:43 resources does exists: false
2023/06/19 22:49:44 invalid polling URL /subscriptions/REDACTED/resourcegroups/rg-test-daa-euw-dev/providers/Microsoft.ManagedIdentity/userAssignedIdentities/mid-test-daa-euw-dev
exit status 1

But, the resource group and the user assigned identity are correctly created, I can see them in my portal.

The resources are created, the exit status is 0 and I get the ID of my user assigned identity.

The script above is self-contained, running it should work.

cat /etc/*release result :

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
lirenhe commented 1 year ago

@raych1, could you take a look?

raych1 commented 1 year ago

Thanks @MathKlim for reporting this issue. I can repro this issue.

Loop in service team to have a look at if managed identity follows same polling logic.

Meanwhile, you might try to use armmsi package to work with managed identity.

github-actions[bot] commented 1 year ago

Hi @MathKlim. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

raych1 commented 1 year ago

Hi @MathKlim , did you try the armmsi package?

MathKlim commented 1 year ago

Hi @MathKlim , did you try the armmsi package?

Hi, sorry for the delay. No, I haven't, I will try the armmsi package tomorrow or wednesday.

github-actions[bot] commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @armleads-azure.

github-actions[bot] commented 10 months ago

Hi @MathKlim. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] commented 10 months ago

Hi @MathKlim, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!