azure-sdk-for-go: CheckExistenceByID and CheckExistence always returning false with Get or GetByID confirming the resources exists

Bug Report

  • Import path of package: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources
  • SDK version: v63.4.0
  • go version: go1.18.1 windows/amd64
  • What happened? I created a code shown below.
// Set the package
package main

import (
	"context"
	"log"
	"testing"

	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
	"github.com/stretchr/testify/assert"
)

// Set the required variables
var subscriptionID = "82d66c37-8d61-4db4-b138-xxxxxxxxxxxx"
var apiVersion = "2022-02-01-preview"
var resourceID = "/subscriptions/82d66c37-8d61-4db4-b138-xxxxxxxxxxxx/resourceGroups/DEXT-EUN-RGRP01/providers/Microsoft.KeyVault/vaults/dexteunautomationkv01"

// Set the function to test resource existsence
func TestAzureKeyVaultExistence(t *testing.T) {
	// Create a context
	ctx := context.Background()

	// Create a new credential
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		log.Fatal(err)
	}

	// Create a new resource client
	resourceClient, _ := armresources.NewClient(subscriptionID, cred, nil)

	// Check if the resource exists
	exists, err := resourceClient.CheckExistenceByID(ctx, resourceID, apiVersion, nil)
	if err != nil {
		log.Fatal(err)
	}
	assert.True(t, exists.Success)
}
  • When I executed the command go test -v, I got the error shown below.
=== RUN   TestAzureKeyVaultExistence
    integration_test.go:31:
                Error Trace:    integration_test.go:31    
                Error:          Should be true
                Test:           TestAzureKeyVaultExistence
--- FAIL: TestAzureKeyVaultExistence (2.83s)
FAIL
exit status 1
FAIL    test.com        4.764s
  • What did you expect or want to happen? I should have a successful output as shown in the snip below.
=== RUN   TestAzureKeyVaultExistence
--- PASS: TestAzureKeyVaultExistence (1.98s)
PASS
ok      test.com        3.437s
  • How can we reproduce it?

    • Create a similar go code as above.
    • Ensure an Azure resource exists.
    • Execute the code to check the resource from the go code.
  • Anything we should know about your environment. The Get-AzKeyVault command shows the resource exists as shown below

Vault Name          : dexteunautomationkv01
Resource Group Name : DEXT-EUN-RGRP01
Location            : northeurope
Resource ID         : /subscriptions/82d66c37-8d61-4db4-b138-xxxxxxxxxxxx/resourceGroups/DEXT-EUN-RGRP01/providers/Microsoft.KeyVault/vaults/dexteunautomationkv01
Tags                : 

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Changing the verb from HEAD to GET the request succeeds, but that shouldn’t be necessary. @lirenhe can you please follow up with the service team about this?