Microsoft Learn

Az.Templatespec PowerShell Module

The Az.Templatespec module provides cmdlets for managing Azure Template Specs. Template Specs are a way to package Azure Resource Manager (ARM) templates and their parameters into a versioned resource. This allows for easier sharing, reuse, and governance of ARM templates across an organization.

Note

Ensure you have the latest version of the Az PowerShell module installed to use these cmdlets effectively. You can update it using Update-Module -Name Az.

Overview

Template Specs enable you to store ARM templates in Azure and define them as a first-class resource. This brings benefits like:

  • Version Control: Templates can be versioned, allowing you to track changes and roll back if necessary.
  • Access Control: RBAC can be applied to Template Specs, controlling who can view, create, or deploy them.
  • Discovery: Easier discoverability of approved templates within your organization.
  • Simplified Deployment: Deployments can reference Template Specs directly, reducing the need to manage individual template files.

Cmdlets

The Az.Templatespec module includes the following cmdlets:

Tip

Run Get-Command -Module Az.Templatespec in your PowerShell session to see a full list of available cmdlets.

Cmdlet Name Description
New-AzTemplateSpec Creates a new Template Spec resource.
Get-AzTemplateSpec Retrieves one or more Template Specs.
Set-AzTemplateSpec Updates an existing Template Spec.
Remove-AzTemplateSpec Deletes a Template Spec.
Export-AzTemplateSpec Exports the contents of a Template Spec.
Invoke-AzTemplateSpecDeployment Deploys a Template Spec.

Examples

Creating a Template Spec

This example creates a new Template Spec named 'my-web-app-template' in the resource group 'my-resource-group' using an ARM template file named 'webAppTemplate.json'.


# Define variables
$subscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$resourceGroupName = "my-resource-group"
$templateSpecName = "my-web-app-template"
$templateFilePath = "./webAppTemplate.json"
$location = "eastus"

# Set the subscription context
Set-AzContext -SubscriptionId $subscriptionId

# Create the Template Spec
New-AzTemplateSpec -ResourceGroupName $resourceGroupName `
                   -Name $templateSpecName `
                   -TemplateFilePath $templateFilePath `
                   -Location $location `
                   -Description "A template for deploying a basic web app." `
                   -Version "1.0.0"
                

Deploying a Template Spec

This example deploys a Template Spec named 'my-web-app-template' using its version '1.0.0'.


# Define variables
$resourceGroupName = "my-deployment-rg"
$templateSpecName = "my-web-app-template"
$templateSpecVersion = "1.0.0"
$location = "eastus"
$deploymentName = "web-app-deploy-$(Get-Date -Format 'yyyyMMddHHmmss')"

# Define parameters for the deployment
$templateSpecParameters = @{
    "hostingPlanName" = "my-app-plan"
    "webAppName" = "my-unique-app-name"
}

# Deploy the Template Spec
Invoke-AzTemplateSpecDeployment -ResourceGroupName $resourceGroupName `
                                -Name $templateSpecName `
                                -Version $templateSpecVersion `
                                -Location $location `
                                -Parameters $templateSpecParameters `
                                -DeploymentName $deploymentName