Skip to content

Commit e311659

Browse files
committed
update
1 parent 539e161 commit e311659

File tree

2 files changed

+99
-34
lines changed

2 files changed

+99
-34
lines changed

articles/azure-resource-manager/resource-group-linked-templates.md

Lines changed: 98 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,53 +18,118 @@ For a tutorial, see [Tutorial: create linked Azure Resource Manager templates](.
1818
1919
## Nested template
2020

21-
To create a nested template, add the [deployments resource type](/azure/templates/microsoft.resources/2019-08-01/deployments) to the parent template, and embed all of the template syntax within the resource. To nest the template within the main template, use the **template** property and specify the template syntax.
21+
To nest a template, add a [deployments resource](/azure/templates/microsoft.resources/deployments) to your main template. In the **template** property, specify the template syntax.
2222

2323
```json
24-
"resources": [
25-
{
26-
"type": "Microsoft.Resources/deployments",
27-
"apiVersion": "2018-05-01",
28-
"name": "nestedTemplate",
29-
"properties": {
30-
"expressionEvaluationOptions": {
31-
"scope": "inner"
32-
},
33-
"mode": "Incremental",
34-
"template": {
35-
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
36-
"contentVersion": "1.0.0.0",
37-
"resources": [
38-
{
39-
"type": "Microsoft.Storage/storageAccounts",
40-
"apiVersion": "2019-04-01",
41-
"name": "[variables('storageName')]",
42-
"location": "West US",
43-
"kind": "StorageV2",
44-
"sku": {
45-
"name": "Standard_LRS"
24+
{
25+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
26+
"contentVersion": "1.0.0.0",
27+
"parameters": {},
28+
"variables": {},
29+
"resources": [
30+
{
31+
"apiVersion": "2017-05-10",
32+
"name": "nestedTemplate1",
33+
"type": "Microsoft.Resources/deployments",
34+
"properties": {
35+
"mode": "Incremental",
36+
"template": {
37+
<nested-template-syntax>
38+
}
4639
}
47-
}
48-
]
49-
}
40+
}
41+
],
42+
"outputs": {
5043
}
51-
}
52-
]
44+
}
5345
```
5446

55-
When using a nested template, you must specify whether template expressions are evaluated within the scope of the parent template or the nested template. For example, the preceding example uses a parameter named `storageName`. You can specify whether that parameter comes from 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.
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.
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`.
50+
51+
```json
52+
{
53+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
54+
"contentVersion": "1.0.0.0",
55+
"parameters": {
56+
},
57+
"variables": {
58+
"exampleVar": "from parent template"
59+
},
60+
"resources": [
61+
{
62+
"apiVersion": "2017-05-10",
63+
"name": "nestedTemplate1",
64+
"type": "Microsoft.Resources/deployments",
65+
"properties": {
66+
"expressionEvaluationOptions": {
67+
"scope": "inner"
68+
},
69+
"mode": "Incremental",
70+
"template": {
71+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
72+
"contentVersion": "1.0.0.0",
73+
"variables": {
74+
"exampleVar": "from nested template"
75+
},
76+
"resources": [
77+
78+
],
79+
"outputs": {
80+
"testVar": {
81+
"type": "string",
82+
"value": "[variables('exampleVar')]"
83+
}
84+
}
85+
}
86+
}
87+
}
88+
],
89+
"outputs": {
90+
"messageFromLinkedTemplate": {
91+
"type": "string",
92+
"value": "[reference('nestedTemplate1').outputs.testVar.value]"
93+
}
94+
}
95+
}
96+
```
5697

5798
> [!NOTE]
5899
>
59-
> 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, convert your nested template to a linked template.
100+
> 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.
60101
61102
The nested template requires the [same properties](resource-group-authoring-templates.md) as a standard template.
62103

63104
## Linked template
64105

65-
To link to an external template, use the **templateLink** property. 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.
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.
107+
108+
```json
109+
{
110+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
111+
"contentVersion": "1.0.0.0",
112+
"parameters": {},
113+
"variables": {},
114+
"resources": [
115+
{
116+
"apiVersion": "2017-05-10",
117+
"name": "nestedTemplate1",
118+
"type": "Microsoft.Resources/deployments",
119+
"properties": {
120+
"mode": "Incremental",
121+
"templateLink": {
122+
"uri": <uri-for-linked-template>
123+
}
124+
}
125+
}
126+
],
127+
"outputs": {
128+
}
129+
}
130+
```
66131

67-
One option is to place your linked template in a storage account, and use the URI for that item.
132+
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.
68133

69134
You can provide the parameters for your external template either in an external file or inline.
70135

@@ -347,7 +412,7 @@ To use the public IP address from the preceding template when deploying a load b
347412

348413
## Deployment history
349414

350-
Resource Manager processes each template as a separate deployment in the deployment history. Therefore, a main template with three linked or nested templates appears in the deployment history as:
415+
Resource Manager processes each template as a separate deployment in the deployment history. A main template with three linked or nested templates appears in the deployment history as:
351416

352417
![Deployment history](./media/resource-group-linked-templates/deployment-history.png)
353418

articles/azure-resource-manager/resource-group-template-functions-resource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ Use `'Full'` when you need resource values that aren't part of the properties sc
477477

478478
The reference function can only be used in the properties of a resource definition and the outputs section of a template or deployment. When used with [property iteration](resource-group-create-multiple.md#property-iteration), you can use the reference function for `input` because the expression is assigned to the resource property. You can't use it with `count` because the count must be determined before the reference function is resolved.
479479

480-
You can't use the reference function in the outputs of a [nested template](resource-group-linked-templates.md#nested-template) to return a resource you've deployed in the nested template. Instead, use a [linked template](resource-group-linked-templates.md#external-template).
480+
You can't use the reference function in the outputs of a [nested template](resource-group-linked-templates.md#nested-template) to return a resource you've deployed in the nested template. Instead, use a [linked template](resource-group-linked-templates.md#linked-template).
481481

482482
If you use the **reference** function in a resource that is conditionally deployed, the function is evaluated even if the resource isn't deployed. You get an error if the **reference** function refers to a resource that doesn't exist. Use the **if** function to make sure the function is only evaluated when the resource is being deployed. See the [if function](resource-group-template-functions-logical.md#if) for a sample template that uses if and reference with a conditionally deployed resource.
483483

0 commit comments

Comments
 (0)