Blog

Get subscription id in an Azure Resource Manager Template

24 Mar, 2016
Xebia Background Header Wave

Recently I was writing an Azure Resource Manager Template to deploy a Web App. The Web App needed some Application settings (like connection strings, etc..) which I wanted to provision during the Resource Manager Template deployment. One of the settings needed was the Azure subscription id where the Web App was created.
I didn’t want to hardcode the subscription id, or provide it through a parameter (which is a way to postpone the hard-coding), so I did a little research and I found the solution.

In Azure RM Template you can use Resource Functions which can evaluate during the deployment run-time settings.

The one I needed was subscription()  which has the following structure:

{
    "id": "/subscriptions/#####",
    "subscriptionId": "#####",
    "tenantId": "#####"
}

This means you can use the function like this:

"parameters": {
  "siteName": {
      "type": "string"
  }
},
"resources": [
   {
      "apiVersion": "2014-06-01",
      "name": "[parameters('siteName')]",
      "type": "Microsoft.Web/Sites",
        "properties": {
            "subscriptionid": "[subscription().subscriptionId]",
            "AzureWebJobsDashboard": "xxxx",
            "AzureWebJobsStorage": "xxxx"
        }
   }
]

There are more nice functions you may need to use like: resourceGroup()resourceId ([resourceGroupName], resourceType, resourceName1, [resourceName2]…).

Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts