Functions in templates

Since we cannot use PowerShell for everything, it is also possible to execute a certain set of functions inside ARM templates. These can be very useful; for example, they can be used to generate a unique string for certain resources, to concatenate variables and parameters, and much more.

For more information on all of the functions you can use, see https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions.

The function uniqueString will deterministically generate seemingly unique strings, depending on the seed that you are using. This function should by no means be seen as a cryptographic hash function. For our intents and purposes, this function generates random strings that can be concatenated with strings fitting your own naming scheme, for example. Take a look at the next code sample to see the template functions in action:

$template.variables = @{
# Two functions at once. Concatenate contoso with a
# unique string. The hash function uniqueString requires a seed
# which is our resource group GUID
storageAccountName = "[concat('contoso', uniquestring(resourceGroup().id))]"
}

# Export and deploy again
$template | ConvertTo-Json -Depth 100 | Out-File -FilePath .StorageAccountFunctions.json -Encoding UTF8

$deployment = @{
Name = 'ThirdDeployment'
ResourceGroupName = $resourceGroupName
TemplateFile = '.StorageAccountFunctions.json'
Verbose = $true
}

# Use your template parameters in the resource group deployment!
New-AzureRmResourceGroupDeployment @deployment -location 'westeurope' -storageAccountType 'Standard_LRS'
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.193.158