1. Answers
  2. Finding Azure Tenant ID

How do I find my Azure Tenant ID?

To find your Azure Tenant ID, you can use the Azure CLI tool or a simple Terraform script to query it programmatically. Here, we’ll demonstrate how to retrieve the Azure Tenant ID by leveraging the Azure Provider and exposing the Tenant ID as an output.

In this example, we’ll use the Azure Provider to fetch the Tenant ID. The code will configure the Azure Provider using your Azure credentials and then output the Tenant ID.

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";

const example = azure.core.getClientConfigOutput({});
export const tenantId = example.apply(example => example.tenantId);

This script does the following:

  1. Configures the Azure Provider.
  2. Uses azurerm_client_config to access the current Azure context and extract the Tenant ID.
  3. Outputs the Tenant ID for easy retrieval.

Overall, this example shows how to set up the necessary configuration and extract the Azure Tenant ID using the Azure Provider.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up