With the self hosted agent installed in the VM ( enabled system-assigned identity), we are facing an issue with the terraform initialization with the below error.
Error: Error inspecting states in the “azurerm” backend:
Error retrieving keys for Storage Account "* ": azure.BearerAuthorizer#WithAuthorization: Failed to refresh the Token for request to https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Storage/storageAccounts//listKeys?api-version=2016-01-01: StatusCode=400 – Original Error: adal: Refresh request failed. Status Code = ‘400’. Response body: {“error”:“unauthorized_client”,“error_description”:"AADSTS700016: Application with identifier ‘null’ was not found in the directory '** '. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
The VM is using user assigned identity. The managed identity is provisioned as Contributor in Subscription level.