Skip to content

Commit aa094d0

Browse files
authored
Merge pull request #106946 from tfitzmac/0309function
add template to user function
2 parents e696892 + e907cd9 commit aa094d0

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

articles/azure-resource-manager/templates/template-user-defined-functions.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: User-defined functions in templates
33
description: Describes how to define and use user-defined functions in an Azure Resource Manager template.
44
ms.topic: conceptual
5-
ms.date: 09/05/2019
5+
ms.date: 03/09/2020
66
---
77
# User-defined functions in Azure Resource Manager template
88

@@ -12,7 +12,7 @@ This article describes how to add user-defined functions in your Azure Resource
1212

1313
## Define the function
1414

15-
Your functions require a namespace value to avoid naming conflicts with template functions. The following example shows a function that returns a storage account name:
15+
Your functions require a namespace value to avoid naming conflicts with template functions. The following example shows a function that returns a unique name:
1616

1717
```json
1818
"functions": [
@@ -38,23 +38,53 @@ Your functions require a namespace value to avoid naming conflicts with template
3838

3939
## Use the function
4040

41-
The following example shows how to call your function.
41+
The following example shows a template that includes a user-defined function. It uses that function to get a unique name for a storage account. The template has a parameter named **storageNamePrefix** that it passes as a parameter to the function.
4242

4343
```json
44-
"resources": [
44+
{
45+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
46+
"contentVersion": "1.0.0.0",
47+
"parameters": {
48+
"storageNamePrefix": {
49+
"type": "string",
50+
"maxLength": 11
51+
}
52+
},
53+
"functions": [
4554
{
46-
"name": "[contoso.uniqueName(parameters('storageNamePrefix'))]",
47-
"apiVersion": "2016-01-01",
48-
"type": "Microsoft.Storage/storageAccounts",
49-
"location": "South Central US",
50-
"tags": {},
51-
"sku": {
52-
"name": "Standard_LRS"
53-
},
54-
"kind": "Storage",
55-
"properties": {}
55+
"namespace": "contoso",
56+
"members": {
57+
"uniqueName": {
58+
"parameters": [
59+
{
60+
"name": "namePrefix",
61+
"type": "string"
62+
}
63+
],
64+
"output": {
65+
"type": "string",
66+
"value": "[concat(toLower(parameters('namePrefix')), uniqueString(resourceGroup().id))]"
67+
}
68+
}
69+
}
5670
}
57-
]
71+
],
72+
"resources": [
73+
{
74+
"type": "Microsoft.Storage/storageAccounts",
75+
"apiVersion": "2019-04-01",
76+
"name": "[contoso.uniqueName(parameters('storageNamePrefix'))]",
77+
"location": "South Central US",
78+
"sku": {
79+
"name": "Standard_LRS"
80+
},
81+
"kind": "StorageV2",
82+
"properties": {
83+
"supportsHttpsTrafficOnly": true
84+
}
85+
}
86+
]
87+
}
5888
```
5989

6090
## Limitations

0 commit comments

Comments
 (0)