Azure Template Specs - Part 1 - Introduction
Azure Template Specs are reusable templates that allow you to define infrastructure-as-code (IaC) resources in Azure.
Characteristics
Because Template Specs can be stored in Resource groups, access can be controlled via Azure role-based access control (Azure RBAC).
Template Specs can be versioned, to be used for fixes or new enhancements. What it provides is an open text string that can be combined with Semantic Versioning1 for controlling versions.
Resources can be provisioned by users without having write access to the template. Only read access is enough to enable resource provisioning, without any modification to templates.
Template Specs can be integrated with any deployment process through scripting via PowerShell, AZ CLI or DevOps pipelines.
Here are some benefits of using Azure Template Specs:
-
Consistency: Azure Template Specs allow you to define infrastructure resources consistently, ensuring that all resources have the same configuration and settings. This consistency helps to reduce errors and simplify maintenance.
-
Reusability: Once you have defined a Template Spec, it can be reused across multiple environments, such as dev, test, and production, saving time and effort.
-
Versioning: Template Specs can be versioned, allowing you to track changes over time and roll back to previous versions if needed.
-
Collaboration: Template Specs can be shared among teams, allowing for collaboration and reducing the time and effort required to develop and deploy infrastructure.
-
Automation: With Azure Template Specs, you can automate the creation of resources in Azure, saving time and reducing the risk of errors.
How to get started
There are different ways to provision Template Specs, by using ARM Templates, Bicep Templates, and combining with PowerShell or Azure CLI.
Because this is an intro post, everything will be exemplified through the Azure Portal. In the next posts, this will be exemplified through scripting.
Create a Template Spec
The Wizard guides us through the different tabs and required fields:
When creating the template specs from the UI, an ARM Template will be required. This is a sample of an Azure Storage V22 which accepts 3 parameters storageAccountType
, location
and storageAccountName
. All of the parameters have default values:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Premium_LRS",
"Premium_ZRS",
"Standard_GRS",
"Standard_GZRS",
"Standard_LRS",
"Standard_RAGRS",
"Standard_RAGZRS",
"Standard_ZRS"
],
"metadata": {
"description": "Storage Account type"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The storage account location."
}
},
"storageAccountName": {
"type": "string",
"defaultValue": "[format('store{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "The name of the storage account"
}
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-09-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {}
}
]
}
Copy the ARM Template and paste into the Edit Template tab:
Always a good practice to introduce tags to help with resources classification and management:
Then review your configuration and create the template spec:
Provisioning is straightforward. The resource is created on Resource Group.
Create a resource from a Template Spec
From here we can create Azure resources from the template, we can simply open the template spec and click Deploy:
This will get us onto a Wizard to help with the configuration settings. It is worth noting that the parameters are auto-populated with the default values specified on the ARM template:
Review and confirm the details to provision the Azure Storage:
Azure Template Specs can help you to streamline your infrastructure management process, reduce errors, and improve collaboration among teams. Reusable components make IaC modular, organizing infrastructure as a software implementation.
Full Series
Azure Template Specs - Part 1 - Introduction
Azure Template Specs - Part 2 - Scripting