Throughout all of our projects we always make sure that we are able to stand up environments for development, testing or production and ensure that we can easily automate that deployment.
On a number of projects we have found that instead of creating a number of environment templates based on variables, we take a slightly different strategy.
We create one template that is not environment specific and then create a number of parameter.json files that contain the particular environment we want to deploy.
The diagram below shows the key differences and advantages.
To implement this strategy we need an environment parameter file, we use an object within the parameter file as a universal single parameter which is used by all the templates. The functionality that ties the two artefacts together is via the dot syntax to access the associated attributes as in the example below.
"[parameters('companyabc').<ATTRIBUTE>]".
Additionally ARM templates allows us structure our parameters using nested objects.
Here’s an example for CompanyABC.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.3.0.0",
"parameters": {
"companyabc": {
"value": {
"databases": {
"server_name": "companyabcpoc",
"server_username": "company1",
"server_password": "password",
},
"storageaccounts": {
…
…
…
},
"eventhubnamespace": {
…
…
…},
}
}
}
}
Here is the associated template file.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.3.0.0",
"parameters": {
"companyabc": {
"type": "object"
}
},
"variables": {
…
…
…
},
"resources": [{
"type": "Microsoft.Sql/servers",
"kind": "v12.0",
"name": "[parameters('companyabc').databases.server_name]",
"apiVersion": "2014-04-01-preview",
"location": "[resourcegroup().location]",
"properties": {
"administratorLogin": "[parameters('companyabc').databases.server_username]",
"administratorLoginPassword": "[parameters('companyabc').databases.server_password]",
"version": "12.0"
},
"resources": [],
"dependsOn": [],
"tags": {
"Creator": "Elastacloud",
"Solution": "elastacloud-data CompanyABC",
}
}
]
}
We are now able to deploy multiple environments using just one template.
In the next post we will look how we use our ARM template approach to automate deployments using VSTS.