The issue is that I have 2 tenant ids (D and V) and 2 subscriptions id (D and V) because I’am working for 2 different clients.
This cmd is for changing the tenant ID
az login --tenant <myTenantID>
And this cmd is for changing the subscription id
az login --subscription <mysubscriptionID>
currently I am working on V subscription/tenant id and I want to switch to D subscription/tenant id.
I have run these commands mentioned above, a browser page opens and i can log in.
But when I run my terraform command init, plan and apply. The terraform code creates the new resource group in the V subscription/tenant id and not in the D subscription/tenant id where I want.
Btw currently my default account is D but still it creates in the V account.
2
Answers
I think you need the
az account
commands.You can list your accounts as below (table for easier reading of the information)
You can query which one is currently your default account using the query flag.
Finally, you can change your account using either of the below commands using the subscription name or subscription Id from the command run earlier to list your subscriptions / accounts.
You can customize your
azurerm
terraform provider as per your requirements by passing the relative argument.Terraform Code
Single Directory Structure (Depends on you but not recommended from my POV)
If you want to manage both tenants from a single directory, with only one
providers.tf
then you have to also use thealias
feature of terraform providers.Per-tenant-directory structure
Technically you can remove these
tenant_id
andsubscription_id
arguments from here but you have to make sure viaaz cli
or environment variables that the correct tenant and subscription id are selected.Similar
providers.tf
file can be used for other subscriptions.This will simplify your configurations and reduce maintenance efforts by a ton.
Important Considerations
Documentation URLs