Rediger

Del via


Develop templates for Azure Stack Hub with Azure Resource Manager

As you develop your app, it is important to have template portability between Azure and Azure Stack Hub. This article provides considerations for developing Azure Resource Manager templates. With these templates, you can prototype your app and test deployment in Azure without access to an Azure Stack Hub environment.

Resource provider availability

The template you plan to deploy must only use Microsoft Azure services that are already available, or in preview, in Azure Stack Hub.

Public namespaces

Because Azure Stack Hub is hosted in your datacenter, it has different service endpoint namespaces than the Azure public cloud. As a result, hard-coded public endpoints in Azure Resource Manager templates fail when you try to deploy them to Azure Stack Hub. You can dynamically build service endpoints using the reference and concatenate functions to retrieve values from the resource provider during deployment. For example, instead of hard-coding blob.core.windows.net in your template, retrieve the primaryEndpoints.blob to dynamically set the osDisk.URI endpoint:

"osDisk": {"name": "osdisk","vhd": {"uri":
"[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2015-06-15').primaryEndpoints.blob, variables('vmStorageAccountContainerName'),
 '/',variables('OSDiskName'),'.vhd')]"}}

API versioning

Azure service versions may differ between Azure and Azure Stack Hub. Each resource requires the apiVersion attribute, which defines the capabilities offered. To ensure API version compatibility in Azure Stack Hub, the following API versions are valid for each resource provider:

Resource Provider apiVersion
Compute 2015-06-15
Network 2015-06-15, 2015-05-01-preview
Storage 2016-01-01, 2015-06-15, 2015-05-01-preview
KeyVault 2015-06-01
App Service 2015-08-01

Template functions

Azure Resource Manager functions provide the capabilities required to build dynamic templates. As an example, you can use functions for tasks such as:

  • Concatenating or trimming strings.
  • Referencing values from other resources.
  • Iterating on resources to deploy multiple instances.

These functions are not available in Azure Stack Hub:

  • Skip
  • Take

Resource location

Azure Resource Manager templates use a location attribute to place resources during deployment. In Azure, locations refer to a region such as West US or South America. In Azure Stack Hub, locations are different because Azure Stack Hub is in your datacenter. To ensure templates are transferable between Azure and Azure Stack Hub, you should reference the resource group location as you deploy individual resources. You can do this using [resourceGroup().Location] to ensure all resources inherit the resource group location. The following code is an example of using this function while deploying a storage account:

"resources": [
{
  "name": "[variables('storageAccountName')]",
  "type": "Microsoft.Storage/storageAccounts",
  "apiVersion": "[variables('apiVersionStorage')]",
  "location": "[resourceGroup().location]",
  "comments": "This storage account is used to store the VM disks",
  "properties": {
  "accountType": "Standard_LRS"
  }
}
]

Next steps