Skip to content

CheckExistenceByID and CheckExistence always returning false with Get or GetByID confirming the resources exists #17809

@kabal2010

Description

@kabal2010

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                : 

Metadata

Metadata

Labels

MgmtThis issue is related to a management-plane library.Resource AuthorizationService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions