37

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'.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
barlow1
  • 631
  • 2
  • 8
  • 12
  • 1
    probably outdated version of azure cli. try using the latest version. or login before doing that command if you didnt login first – 4c74356b41 Aug 18 '18 at 18:00
  • Thanks for responding. I'm using version 2.044. see following : xxxx@Azure:~$ az --version azure-cli (2.0.44) – barlow1 Aug 18 '18 at 19:20
  • Any more thoughts as to why I'm getting the error message? – barlow1 Aug 18 '18 at 19:38
  • 1
    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 rights – 4c74356b41 Aug 18 '18 at 20:00
  • 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? – barlow1 Aug 18 '18 at 20:39
  • I am assuming you're familiar with Azure Cloud shell? – barlow1 Aug 18 '18 at 20:40
  • try another browser, try incognito mode. same command works for me. – 4c74356b41 Aug 18 '18 at 20:54
  • This won't work regardless of browser or incognito. What output did you get? – barlow1 Aug 18 '18 at 21:37
  • subid and tenantid, like i said this means you are not logged in or dont have permissions – 4c74356b41 Aug 19 '18 at 06:09
  • 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 tenantId – barlow1 Aug 19 '18 at 08:35
  • 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 properly – 4c74356b41 Aug 19 '18 at 09:05
  • 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}" ? – barlow1 Aug 19 '18 at 11:08
  • @barlow1 If the answer is helpful or for more help, please let me know. – Charles Xu Aug 23 '18 at 02:39

11 Answers11

56

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
ita
  • 762
  • 5
  • 9
29

Just log in again

az login

That will update the subscriptions you belong.

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

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
4

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)

Roushan
  • 264
  • 2
  • 14
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.

DarckBlezzer
  • 4,578
  • 1
  • 41
  • 51
shaonm
  • 81
  • 1
  • 1
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.

Sam
  • 131
  • 1
  • 3
2

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.

Luke Schoen
  • 674
  • 6
  • 23
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.

Gwamaka Charles
  • 1,479
  • 9
  • 12
1

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).

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
  • 1
    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. – Wim Aug 26 '21 at 10:56
  • 1
    @Wim Thanks for this comment, just retry worked. Weird but as long as working I am fine ;) – Jaydeep Soni Aug 31 '22 at 12:18
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

0

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.

atconway
  • 20,624
  • 30
  • 159
  • 229