la-di-da
la-di-da

Reputation: 48

The Vault '' not found within subscription

The Vault '' not found within subscription even though we have access to the subscription. I am following the documentation and trying to grant access to our Azure Key Vault:

Grant access to your key vault

When I try the command to create an access policy for our Key Vault that grants secret permission to our user account, we are getting the following error:

Key Vault Not Found Within Subscription

We tried adding the --debug command as follows; however, we're still unclear as to why our Key Vault is not found under the Subscription ID in our Azure portal:

Key Vault Not Found

https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-python?tabs=azure-powershell%2Cazure-cli

We used az login, and it looks like we have access to the correct subscription based off of the output below since the "id" matches our Subscription ID:

az login subscription

Upvotes: 1

Views: 1315

Answers (1)

la-di-da
la-di-da

Reputation: 48

Edit: I found how it's suppose to work!

First, you need to make sure you are logged into the correct subscription. https://learn.microsoft.com/en-us/powershell/azure/context-persistence?view=azps-8.2.0

Context is often picked by default and does not always go where you want it to. You can run Get-AzSubscription to check whether the correct subscription is listed.

Originally, when I ran Get-AzSubscription in PowerShell, I got the following error:

enter image description here

Turns out you need to install the Az module in PowerShell. You can also try running the command instead: az account tenant list && az account show --output table

Since context is often picked by default and does not always go where you want it to, you can set the default subscription as follows:

After logging into Azure, using e.g. Connect-AzAccount in PowerShell (version 7+), or whichever command you use to login, you can use the Update-AzConfig -DefaultSubscriptionForLogin <> command in PowerShell to update the default subscription so that in the future, it will always choose your specified default subscription.

Example of 3 different ways to change the default subscription:

az account set --subscription "XX-XXXXX-XXX-XXX-XXXX-XXX"

Set-AzContext -Subscription 'XX-XXXXX-XXX-XXX-XXXX-XXX'

Update-AzConfig -DefaultSubscriptionForLogin YourSubscriptionNameHere

You can check to make sure the default was changed by using the command:

az account show --output table

Upvotes: 2

Related Questions