Reputation: 391
I need to use a tenant (directory tenant) name in my ARM templates (especially when creating Web Apps).
It is possible to get subscription name using
subscription().displayName
however, how can I get my associated directory tenant name?
The expressions like [subscription().tenantId.displayName]
or [subscription().tenantId.Name]
aren't working and also I'm unable to find any presence of this property on the web.
The way I won't hardcode it is that it can be easily changed by subscription owner or account admin that's why I'm looking for some existing variable\parameter\etc
Upvotes: 3
Views: 12073
Reputation: 1
You could run a deployment script as your first resource. Then, in powershell write the tenant name as a tag to the resource group your arm template is deploying to. Youll need to create a managed identity in the deployment too.
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-script-template
Connect-AzAccount -identity
$TN = (Get-AzTenant).Name
$Tags += @{"TenantName"=$TN}
Set-AzResourceGroup -Name <your-resource-group-name> -Tag $Tags
Then in you arm template, just reference
"[resourceGroup().tags.TenantName]"
Upvotes: 0
Reputation: 843
The tenantId is now available with template functions. Use the subscription function: subscription().
Try the following output examples for reference:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"subscriptionOutput": {
"value": "[subscription()]",
"type" : "object"
}
}
}
For the tenant id:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [],
"outputs": {
"subscriptionOutput": {
"value": "[subscription().tenantId]",
"type" : "object"
}
}
}
Reference:
Upvotes: 14
Reputation: 72191
There is no way to do this. you can only get these values back:
{
"id": "/subscriptions/{subscription-id}",
"subscriptionId": "{subscription-id}",
"tenantId": "{tenant-id}",
"displayName": "{name-of-subscription}"
}
Upvotes: 2