48

I'm trying to create a Service Principal account using the instructions here

https://learn.microsoft.com/en-us/azure/media-services/latest/stream-files-tutorial-with-api#examine-the-code-that-uploads-encodes-and-streams

However when I run the command

az ams account sp create --account-name *media_service_account_name* --resource-group *resource_group_name*

Where media_service_account_name is the name shown for the media service I have created and resource_group_name the name of the resource group shown on the same page.

The problem is I get the message ResourceGroupNotFound:

Resource group 'resource_group_name' could not be found.

I just can't see what I am doing wrong. Any help appreciated.

chrki
  • 6,143
  • 6
  • 35
  • 55
RadarBug
  • 707
  • 1
  • 6
  • 13
  • 2
    My problem was that I had multiple subscriptions for the account and I needed to set the subscription related to the resource group first – RadarBug Nov 23 '18 at 12:42

6 Answers6

122

If you have multiple subscriptions, set your subscription first and then try:

  • To list all subscriptions - az account list --output table
  • To set your subscription - az account set --subscription <subscription-id>
xalves
  • 320
  • 1
  • 18
Swapnil Pandit
  • 1,221
  • 1
  • 8
  • 3
  • 2
    In Azure Powershell, I needed to run "Set-Azcontext " in order for my subscription to change - as per @ddmh's answer. - However your answer made me aware of the reason for my error, thanks :) – Daniël J.M. Hoffman Feb 09 '22 at 11:05
  • When you run "az account list" as shown, check which subscription ID is set with IsDefault true. It is probably not the one you want, so the "az account set" command is used to change to the correct subscription, then your command that was failing to find the resource group will probably work. I found this useful on "az vm deallocate" when it said it couldn't find the resource group - changed to the correct subscription, and the vm deallocate worked as required. – hairysocks Nov 09 '22 at 08:39
  • The set subscription solved my issue. It is strange that I am using command "az network nsg rule list" and I even added parameter --subscription to it, but still failed. – civic.LiLister Aug 29 '23 at 18:31
11

I had the same issue and verified the subscription with az account show, but what I was missing is that I was working in powershell and needed to set the correct subscription in powershell. Verify context: Get-Azcontext Set context: Set-Azcontext <subscription_id>

dahol
  • 323
  • 3
  • 7
9

Kindly follow these steps to get over an above error:

  1. az login It will ask you to provide credentials

  2. az account list --o table // Will list all subscription

Set your subscription on which you want to execute query 3. az account set --subscription "VS Subscription"

Hope it will help

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Sachin Kalia
  • 1,027
  • 14
  • 24
7

You may have multiple subscriptions. Set the subscription to default which you want to use in CLI.

Reference: https://learn.microsoft.com/en-us/cli/azure/manage-azure-subscriptions-azure-cli?view=azure-cli-latest

double-beep
  • 5,031
  • 17
  • 33
  • 41
user11678229
  • 71
  • 1
  • 2
  • 1
    Welcome to StackOverflow! Please include helpful lines of code and plenty of explanation in your answers. You can distinguish a line of code with two accents (`) on either side of the code, to render a result like ``this``. – Grant Noe Jun 20 '19 at 21:06
  • Thank you for this answer! A simple thing like this - left off the Azure documentation walk-through I was using (re. opening a command-line connected to an Azure Kubernetes cluster) - resolved hell for me being unable to "see" the resource group. For others, from the link provided, set the Azure account as follows: `az account list --output table` to view a list of accounts - and - assuming the desired account is in the list - issue `az account set --subscription ""`, at which point, for me at least, the `Resource group not found` error went away. – Dan Nissenbaum Jul 14 '19 at 03:24
  • Thank you very much for this answer. Saved me hours of research. – Vincent Engel Sep 24 '19 at 08:43
  • microsoft links are anything but permalinks. please include the actual answer in your answer i.e,. the cli command to set a default subscription – Greg Woods Oct 19 '20 at 22:36
6

I was running a task: AzureCLI@2 in azure pipeline for creating an azure vwan. I put az account set --subscription xxxxxxx-xxxx-xxx-xxxx-xxxxxxxxx but it still didn't work and was throwing:

ERROR: (ResourceGroupNotFound) Resource group 'test-rg' could not be found.

Then I added --subscription "xxxxxxx-xxxx-xxx-xxxx-xxxxxxxxx" at the end of he az network vwan create even though it wasn't shown in the documentation.

Here's how I did:

az network vwan create --name testwan01 --resource-group test-rg --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" --type Standard

Hope it helps if you are running it from some orchestration tools like Jenkins or Azure pipelines.

qazaqbala
  • 61
  • 1
  • 1
1

Keep in mind that Resource Groups in Azure are things that you create, so the article was only providing an example of a Resource Group name.

The command to create the service principal expects you to use the resource group that you used to create your media service account.

az ams account sp create --account-name amsaccount --resource-group **amsResourceGroup**

Make sure that you are using the right resource group name that you used when you created your Media Services account first, and use a unique named one in the same region as your account. I usually call az group create before creating a new account to put it into it's own Resource Group along with the storage account I create for it.

Example Create a new resource group named "MyResourceGroup" in the West US region.

az group create -l westus -n 

Hope that helps!

johndeu
  • 2,494
  • 1
  • 11
  • 10
  • I think I may be confused as to what resource group is being talked about. If I run az group list I only see one resource group but if I login into the Azure dashboard with the same account there are 36 resource groups but not the one listed by the Azure CLI – RadarBug Nov 22 '18 at 09:14
  • Either way whichever resource group name I use I always get the same message – RadarBug Nov 22 '18 at 09:26
  • Did you check to make sure you were logged into the right subscription via both the portal and the CLI? Otherwise, it may be a permission issue on your subscription. – johndeu Nov 22 '18 at 16:07
  • Try "az account show" and make sure the account you are logged into in the CLI is the right one. – johndeu Nov 22 '18 at 16:08
  • I just re-checked, and was able to run this successfully in my own MSDN account. So if you are hitting an error, you may want to pen a support ticket on your subscription. az ams account sp create -a build18 --resource-group build2018 --role Owner --years 2 – johndeu Nov 22 '18 at 16:13