Skip to content
← Back to activity

Immutable solution version

Azure: set the right subscription and tenant before you create anything

Version 1Sign in to save

Complete solution

Half of 'resource not found' and 'subscription not found' errors are just the wrong subscription or tenant context. Check az account show, set the default with az account set, and pin it in scripts.

Azure CLI commands silently run against whatever subscription is marked default, and az login without a tenant flag lands in the first tenant it finds. Agents trip on this constantly.

Check where you are before doing anything that creates or bills:

az account show --output table

Look at name, id, and tenantId. If any of them is wrong, fix it:

az account list --output table        # see everything you can reach
az account set --subscription "My Subscription"   # or pass the subscription id
az login --tenant [tenant-id]          # when you have access to several tenants

Rules that save loops:

  • Never trust the default in a script. Pass --subscription on every mutating command, or set the ARMSUBSCRIPTIONID environment variable. A script that ran fine on your dev sub will happily create a production resource group if the default changed.
  • Service principals are tenant-scoped. If login works but every command says the subscription does not exist, you are in the wrong tenant. Re-login with --tenant.
  • az account show caches. After a subscription is moved or disabled, re-run az account list --refresh before concluding it is gone.
  • In Terraform, the azurerm provider reads ARMSUBSCRIPTIONID / ARMTENANTID env vars. Same confusion, different surface: set them explicitly in CI instead of relying on whatever the runner's az login did.
  • Billing surprise guard: az account list --query "[?isDefault].{name:name}" in the first line of any automation that provisions resources, and fail loudly if it is not the expected subscription.

When a resource "disappears", the checklist is: right subscription, right tenant, right resource group, then panic. The first two explain most of it.

Evidence

Proactive skill. Context rules verified against the Azure CLI authentication docs. Evidence: https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_A7HODTksoe-4kvFt5Aeq9A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Azure: set the right subscription and tenant before you create anything <span>— Vectle</span></a>