You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -44,9 +44,55 @@ To nest a template, add a [deployments resource](/azure/templates/microsoft.reso
44
44
}
45
45
```
46
46
47
-
When using a nested template, you must specify whether template expressions are evaluated within the scope of the parent template or the nested template. You set the scope through the `expressionEvaluationOptions` property. By default, the `expressionEvaluationOptions` property is set to `outer`, which means it uses the parent template scope. Set the value to `inner` to scope expressions to the nested template.
47
+
The following example deploys a storage account through a nested template.
48
48
49
-
The following template demonstrates how template expressions are resolved according to the scope. It contains a variable named `exampleVar` in the parent template and the nested template. When scope is set to `inner`, it returns `from nested template`. If you changed scope to `outer`, it would return `from parent template`.
When using a nested template, you must specify whether template expressions are evaluated within the scope of the parent template or the nested template. The scope determines how parameters, variables, and functions like [resourceGroup](resource-group-template-functions-resource.md#resourcegroup) and [subscription](resource-group-template-functions-resource.md#subscription) are resolved.
92
+
93
+
You set the scope through the `expressionEvaluationOptions` property. By default, the `expressionEvaluationOptions` property is set to `outer`, which means it uses the parent template scope. In the preceding example, the scope isn't set so the value of the `storageAccountName` parameter is retrieved from the parent template. Set the value to `inner` to scope expressions to the nested template.
94
+
95
+
The following template demonstrates how template expressions are resolved according to the scope. It contains a variable named `exampleVar` that is defined in both the parent template and the nested template. It returns the value of the variable.
50
96
51
97
```json
52
98
{
@@ -95,15 +141,130 @@ The following template demonstrates how template expressions are resolved accord
95
141
}
96
142
```
97
143
144
+
The value of the variable changes based on the scope. The following table shows the results for both scopes.
145
+
146
+
| Scope | Output |
147
+
| ----- | ------ |
148
+
| inner | from nested template |
149
+
| outer (or default) | from parent template |
150
+
151
+
The following example deploys a SQL server and retrieves a key vault secret to use for the password. The scope is set to `inner` because it dynamically creates the key vault ID and passes it as a parameter to the nested template.
> When scope is set to `outer`, you can't use the `reference` function in the outputs section of a nested template for a resource you have deployed in the nested template. To return the values for a deployed resource in a nested template, either use inner scope or convert your nested template to a linked template.
101
264
102
-
The nested template requires the [same properties](resource-group-authoring-templates.md) as a standard template.
103
-
104
265
## Linked template
105
266
106
-
To link a template, add a [deployments resource](/azure/templates/microsoft.resources/deployments) to your main template. In the **templateLink** property, specify the URI of the template to include.
267
+
To link a template, add a [deployments resource](/azure/templates/microsoft.resources/deployments) to your main template. In the **templateLink** property, specify the URI of the template to include. The following example links to a template that deploys a new storage account.
107
268
108
269
```json
109
270
{
@@ -114,12 +275,13 @@ To link a template, add a [deployments resource](/azure/templates/microsoft.reso
@@ -131,11 +293,11 @@ To link a template, add a [deployments resource](/azure/templates/microsoft.reso
131
293
132
294
You can't specify a local file or a file that is only available on your local network. You can only provide a URI value that includes either **http** or **https**. Resource Manager must be able to access the template. One option is to place your linked template in a storage account, and use the URI for that item.
133
295
134
-
You can provide the parameters for your external template either in an external file or inline.
296
+
You don't have to provide the `contentVersion` property for the template or parameters. If you don't provide a content version value, the current version of the template is deployed. If you provide a value for content version, it must match the version in the linked template; otherwise, the deployment fails with an error.
135
297
136
-
### External parameters
298
+
### Parameters for linked template
137
299
138
-
When providing an external parameter file, use the **parametersLink** property:
300
+
You can provide the parameters for your linked template either in an external file or inline. When providing an external parameter file, use the **parametersLink** property:
139
301
140
302
```json
141
303
"resources": [
@@ -158,13 +320,7 @@ When providing an external parameter file, use the **parametersLink** property:
158
320
]
159
321
```
160
322
161
-
You don't have to provide the `contentVersion` property for the template or parameters. If you don't provide a content version value, the current version of the template is deployed. If you provide a value for content version, it must match the version in the linked template; otherwise, the deployment fails with an error.
162
-
163
-
### Inline parameters
164
-
165
-
Or, you can provide the parameter inline. You can't use both inline parameters and a link to a parameter file. The deployment fails with an error when both `parametersLink` and `parameters` are specified.
166
-
167
-
To pass a value from the main template to the linked template, use the **parameters** property.
323
+
To pass parameter values inline, use the **parameters** property.
168
324
169
325
```json
170
326
"resources": [
@@ -186,9 +342,11 @@ To pass a value from the main template to the linked template, use the **paramet
186
342
]
187
343
```
188
344
345
+
You can't use both inline parameters and a link to a parameter file. The deployment fails with an error when both `parametersLink` and `parameters` are specified.
346
+
189
347
## Using copy
190
348
191
-
To create multiple instances of a resource with a nested template, add the copy element at the level of the **Microsoft.Resources/deployments** resource.
349
+
To create multiple instances of a resource with a nested template, add the copy element at the level of the **Microsoft.Resources/deployments** resource. Or, if the scope is inner, you can add the copy within the nested template.
192
350
193
351
The following example template shows how to use copy with a nested template.
194
352
@@ -205,6 +363,9 @@ The following example template shows how to use copy with a nested template.
0 commit comments