I am running something like the following to get some costs in Azure
az login --service-principal --username <clientid> --password <pwd> --
tenant <tenantid>
az account set --subscription <test_subscription>
azure-cost accumulatedCost -s 00000000-0000-0000-0000-000000000000
But this gives an error that it cant find my subscription that i set, ie test_subscription
So i did what the error suggested
az login --service-principal -u <clientid> -p <clientsecret> --tenant <tenantid>
It still gives the error that test_subscription doesnt exist.
I used to use
az login -u [email protected] -p VerySecret
az account set --subscription "test_subscription"
But because [email protected] uses mfa , it says that it wont work .
How can i fix this ?
Need to check below:
Execute az account list
CLI command and verify the logged in accounts as shown below. Check if the providing test_subscription
has existed in the retrieved accounts list.
Try clearing all the logged in accounts in the current console environment with az account clear
command and relog in with the az login
command.
Once logged in, check the subscription details along with the username with az account show
command.
Instead of passing a subscription name <test_subscription>
, try providing the subscription Id as shown in the below way.
az account set --subscription "Subscription_ID"
Also verify whether the subscription has existed under the specific tenant directory by passing a search phase query as given below. If found, then try setting the subscription again with the above command.
az account list --query "[?contains(name,'JAHNAVI')].{SubscriptionName:name, SubscriptionID:id, TenantID:tenantId}" --output table
Refer multiple subscriptions management in Azure CLI.
If still the issue persists, try logging in with the managed identity.