Search code examples
azurepowershellazure-storageazure-resource-group

Azure CLI SubscriptionNotFound Error Despite Correct Subscription and Owner Role


I'm encountering a persistent issue with the Azure CLI where I receive a SubscriptionNotFound error when attempting to create a storage resource from powershell and bash, despite having confirmed that the subscription ID is correct and that I have the Owner role on the subscription. This issue persists across different environments, including local Azure CLI (with both powershell and bash) and Azure Cloud Shell (in the actual webpage portal).

I created an Azure subscription within the past fews days. I logged into Azure CLI with az login. A dialogue popped up and I clicked on my Microsoft account. It gave a printout that looked like this:

PS E:\Dev\path\to\pwd> az login
Please select the account you want to log in with.

Retrieving tenants and subscriptions for the selection...

[Tenant and subscription selection]

No     Subscription name     Subscription ID                       Tenant
-----  --------------------  ------------------------------------  -----------------
[1] *  Azure subscription 1  MY_SUBSCRIPTION_ID_HERE               Default Directory

The default is marked with an *; the default tenant is 'Default Directory' and subscription is 'Azure subscription 1' (MY_SUBSCRIPTION_ID_HERE).

Select a subscription and tenant (Type a number or Enter for no changes): 1

Tenant: Default Directory
Subscription: Azure subscription 1 (MY_SUBSCRIPTION_ID_HERE)

[Announcements]
With the new Azure CLI login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink/?linkid=NUMBER_HERE_I_DONT_RECOGNIZE

If you encounter any problem, please open an issue at https://aka.ms/azclibug

[Warning] The login output has been updated. Please be aware that it no longer displays the full list of available subscriptions by default.

PS E:\Dev\path\to\pwd> 

I successfully created a group resource with:

az group create --name MY_GROUP_RESOURCE_NAME --location eastus

But then I ran:

az storage account create --name MY_STORAGE_NAME --location eastus --resource-group MY_GROUP_RESOURCE_NAME --sku Standard_LRS

And I got:

(SubscriptionNotFound) Subscription MY_SUBSCRIPTION_ID_HERE was not found.
Code: SubscriptionNotFound
Message: Subscription MY_SUBSCRIPTION_ID_HERE was not found.

To fix the problem I tried running:

az account list --output table

Which printed out:

Name                  CloudName    SubscriptionId                        TenantId                              State    IsDefault
--------------------  -----------  ------------------------------------  ------------------------------------  -------  -----------
Azure subscription 1  AzureCloud   MY_SUBSCRIPTION_ID_HERE               MY_TENANT_ID_HERE                     Enabled  True

I set the SubscriptionId manually with:

az account set --subscription MY_SUBSCRIPTION_ID_HERE

But I still got the same error when I ran:

az storage account create --name MY_STORAGE_NAME --location eastus --resource-group MY_GROUP_RESOURCE_NAME --sku Standard_LRS

Solution

  • Just check the resource provider registered in subscription or not.

    enter image description here

    Reference here