The subscription of xxx' doesn't exist in cloud 'AzureCloud'
Asked Answered
M

11

41

I'm trying to follow the example of how to Install and configure Terraform to provision VMs and other infrastructure into Azure using Azure Cloud shell as described here:

The following command provided the subscription id and tenant id:

az account show --query "{subscriptionId:id, tenantId:tenantId}"

However, the command provided the following error:

The subscription of '' doesn't exist in cloud 'AzureCloud'.

Matildamatilde answered 18/8, 2018 at 17:47 Comment(13)
probably outdated version of azure cli. try using the latest version. or login before doing that command if you didnt login firstRola
Thanks for responding. I'm using version 2.044. see following : xxxx@Azure:~$ az --version azure-cli (2.0.44)Matildamatilde
Any more thoughts as to why I'm getting the error message?Matildamatilde
did you read my question? both parts? your version appears to be latest. so did you login? can you do something like: az account list? does it return anything? if not you need to login or check your rightsRola
When I enter az account list I get all of my details, like tenantId, subscriptionID etc.. I automatically login when I access Azure Cloud shell. Otherwise, I''m not sure what you mean, when you ask if I read both parts of your question?Matildamatilde
I am assuming you're familiar with Azure Cloud shell?Matildamatilde
try another browser, try incognito mode. same command works for me.Rola
This won't work regardless of browser or incognito. What output did you get?Matildamatilde
subid and tenantid, like i said this means you are not logged in or dont have permissionsRola
If I wasn't logged in it wouldn't be possible for me to get my subid and tenantId. As I mentioned above when I enter az account list I get my subId and tenantIdMatildamatilde
try doing this: az account list --query "[].{x:id, z:tenantId}" anyway, i dont really understand your problem, just lookup tenantid and subid without this command if you cannot type or copy\paste properlyRola
I entered the command you suggested, and it was successful. The question is why I'm getting the error 'The subscription of '' doesn't exist in cloud 'AzureCloud' when I enter the command az account set --subscription="${SUBSCRIPTION_ID}" ?Matildamatilde
@Matildamatilde If the answer is helpful or for more help, please let me know.Squire
S
4

Test the link you posted and get the same error, the screenshot below: enter image description here

It seems that because you are log in to Azure Portal and there is a tenant which you also logged in. If the tenant only has one subscription, then you set the subscription in another tenant with the command az account set --subscription="${SUBSCRIPTION_ID}", you will get the error:

The subscription of 'xxxx' doesn't exist in cloud 'AzureCloud'

You needn't use the command az account set --subscription="${SUBSCRIPTION_ID}" if the tenant only has one subscription. If you want to use, please use the subscription Id show you. The test result as the screenshot below: enter image description here

Squire answered 20/8, 2018 at 3:28 Comment(1)
this accepted one is totally wrong answer.Zaxis
M
60

For anyone finding this question based on the title but with a different problem to the OP.

Symptoms:

  • subscription isn't showing in az account list output
  • az account set -s subscription_id fails with error message in title

Possible solution:

  • You need to re-auth the cli with az login
Melena answered 9/12, 2019 at 6:15 Comment(0)
B
33

Just log in again

az login

That will update the subscriptions you belong.

Bax answered 7/2, 2020 at 17:3 Comment(2)
Worked for me, logging in refreshed/cleared the cache of the subscriptions i had access toBlatt
Yeah, az logout, az login fixed it for me. It must pull the subscriptions down when you log in.Rigi
W
5

Sometime re-login (az login) also does not work. Try something like:

  1. az logout and then az login. (Here, when you paste the Login URL & Code, then try to use Browser Incognito mode)

    OR

  2. If you are using linux machine, then follow below steps. It worked for me.

    a) sudo az login. b) sudo az account set --subscription Your Subscription ID c) sudo az acr login -n Your Container Registry Name (You use your desired command instead of this acr command)

Watt answered 21/1, 2022 at 10:53 Comment(1)
It says I still have 3 hours in the sandbox, but the subscription actually just disappeared for me and doesn't show up in my subscriptions page and the directory says it has no subscriptions. "/shrug"Holman
S
4

Test the link you posted and get the same error, the screenshot below: enter image description here

It seems that because you are log in to Azure Portal and there is a tenant which you also logged in. If the tenant only has one subscription, then you set the subscription in another tenant with the command az account set --subscription="${SUBSCRIPTION_ID}", you will get the error:

The subscription of 'xxxx' doesn't exist in cloud 'AzureCloud'

You needn't use the command az account set --subscription="${SUBSCRIPTION_ID}" if the tenant only has one subscription. If you want to use, please use the subscription Id show you. The test result as the screenshot below: enter image description here

Squire answered 20/8, 2018 at 3:28 Comment(1)
this accepted one is totally wrong answer.Zaxis
O
3

Faced same problem today. Ran the following commands in below sequence

connect-azaccount az account list --all --output table

I could not see the new subscription where I was given access today only tried to run connect-azaccount multiple times. This was very frustrating. Then I drank a cup of coffee and ran the below command

az login

Then I ran the below command again

az account list --all --output table

Now I could see all the subscriptions including the one where I was added today.

I am very happy now.

Osage answered 21/1, 2020 at 18:52 Comment(0)
P
3

I'm not sure if this really pertains to this question, but this is where I landed while debugging a similar error message, so if anybody else runs into this same issue, the problem I had was that I had run the command with sudo. After running it as my normal user, it worked fine.

Pic answered 16/12, 2021 at 15:35 Comment(0)
A
3

I was running into this error in an Azure DevOps build pipeline using the Azure CLI task and a manual service connection. My issue was that my new service principal had no perms to anything in the subscription. As soon as I gave it contributor access to the resource group where I wanted to deploy to, the error disappeared.

Accustom answered 1/2, 2022 at 23:44 Comment(0)
L
2

I experienced this when using Azure cli through the AzureCLI@2 task, e.g.:

- task: AzureCLI@2
  displayName: 'My task'
  inputs:
    azureSubscription: my-subscription
    scriptType: ps
    scriptLocation: inlineScript
    arguments:
      -c container-name `
      --account-name my-account
    inlineScript: |
      az storage blob lease break -b terraform.tfstate

The executing server had Azure cli v.2.0.69 installed, and the error went away after upgrading the CLI to the newest version (2.27.2 as of writing).

Lelialelith answered 26/8, 2021 at 9:10 Comment(2)
We had this happen using the default MS hosted agents. Likely due to this version issue. A retry solved it, when running it on an agent with the latest CLI.Nmr
@Nmr Thanks for this comment, just retry worked. Weird but as long as working I am fine ;)Vella
D
1

You probably have multiple accounts and want to access a subscription that's available under a different account from the one that you are currently logged in. So, run az logout then run az login which will open your browser so you can login to azure! now select the account you want to use and login. This will resolve the issue as it did for me.

Disconsider answered 29/6, 2021 at 17:20 Comment(0)
M
1

Another way this issue can happen is if you're trying to use different azure subscriptions/logins, and the CLI is picking up the wrong subscription already logged into from your default browser. If you have a separate subscription logged into Azure in an incognito tab and want to use that for the Azure CLI run the following command instead:

az login --use-device-code

That will generate a code to copy. The in the incognito tab you're logged into with the correct Azure account, open a new tab and go to the following link: https://microsoft.com/devicelogin

Provide the copied code and then your CLI command terminal will now use the correct subscription and login you desire.

Mandrake answered 10/5, 2023 at 22:11 Comment(1)
Yep this way i was able to login and see al the tenants i have access to. I just had to run az account set --subscription xxx-xxx afterwards to set the one i want as defaultEasterling
E
0

first go to your machine and type az login It will give you one url, copy and past it on browser , it will ask code which you will fins it on your machine where you execute az login command just copy and past. This process will ask you your azure account detail to verify, give your azure account info. After successful verification close window. then execute below command az account set --subscription **************************** az aks get-credentials --resource-group ********* --name *********

Now you connected to your azure K8 cluster

Entelechy answered 26/8, 2021 at 5:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.