Get subscription id in an Azure Resource Manager Template

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:

JavaScript

1

2

3

4

5

{

"id":"/subscriptions/#####",

"subscriptionId":"#####",

"tenantId":"#####"

}

This means you can use the function like this:

JavaScript

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

"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]…).

Share this:

Author: Marco Mansi

Focus and dedication to everything that has to do with technology and, most of all, software development and architecture is what describes Marco.
Marco is curious and interested in everything that is new and seeks to understand the more quickly the potential and the ability to implement these technologies in the real world.
Marco loves open source and thinks that sharing knowledge is the key to make better things.
View all posts by Marco Mansi