Skip to content

Commit a0f03d9

Browse files
committed
split resource content
1 parent dcdf10b commit a0f03d9

File tree

4 files changed

+26
-131
lines changed

4 files changed

+26
-131
lines changed
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
title: Reference existing resource in Bicep
33
description: Describes how to reference a resource that already exists.
4-
author: mumian
5-
ms.author: jgao
64
ms.topic: conceptual
7-
ms.date: 02/03/2022
5+
ms.date: 02/04/2022
86
---
97

10-
# Existing resources
8+
# Existing resources in Bicep
119

12-
To reference a resource that's outside of the current Bicep file, use the `existing` keyword in a resource declaration.
10+
To reference an existing resource that isn't deployed in your current Bicep file, declare the resource with the `existing` keyword. Use the `existing` keyword when you're deploying a resource that needs to get a value from an existing resource. You access the existing resource's properties through its symbolic name.
1311

14-
## Syntax
12+
The resource isn't redeployed when referenced with the `existing` keyword.
1513

16-
When using the `existing` keyword, provide the `name` of the resource. The following example gets an existing storage account in the same resource group as the current deployment.
14+
## Same scope
15+
16+
The following example gets an existing storage account in the same resource group as the current deployment. Notice that you provide only the name of the existing resource. The properties are available through the symbolic name.
1717

1818
```bicep
1919
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
@@ -23,7 +23,9 @@ resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
2323
output blobEndpoint string = stg.properties.primaryEndpoints.blob
2424
```
2525

26-
Optionally, you can set the `scope` property to access a resource in a different scope. The following example references an existing storage account in a different resource group.
26+
## Different scope
27+
28+
Set the `scope` property to access a resource in a different scope. The following example references an existing storage account in a different resource group.
2729

2830
```bicep
2931
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
@@ -34,12 +36,12 @@ resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
3436
output blobEndpoint string = stg.properties.primaryEndpoints.blob
3537
```
3638

37-
If you attempt to reference a resource that doesn't exist, you get the `NotFound` error and your deployment fails.
38-
3939
For more information about setting the scope, see [Scope functions for Bicep](bicep-functions-scope.md).
4040

41-
The preceding examples don't deploy the storage account. Instead, you can access properties on the existing resource by using the symbolic name.
41+
## Troubleshooting
42+
43+
If you attempt to reference a resource that doesn't exist, you get the `NotFound` error and your deployment fails. Check the name and scope of the resource you're trying to reference.
4244

4345
## Next steps
4446

45-
- To conditionally deploy a resource, see [Conditional deployment in Bicep](./conditional-resource-deployment.md).
47+
For the syntax to deploy a resource, see [Resource declaration in Bicep](resource-declaration.md).

articles/azure-resource-manager/bicep/resource-declaration.md

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
22
title: Declare resources in Bicep
33
description: Describes how to declare resources to deploy in Bicep.
4-
author: mumian
5-
ms.author: jgao
64
ms.topic: conceptual
7-
ms.date: 11/12/2021
5+
ms.date: 02/04/2022
86
---
97

108
# Resource declaration in Bicep
@@ -187,111 +185,8 @@ resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
187185
}
188186
```
189187

190-
## Dependencies
191-
192-
When deploying resources, you may need to make sure some resources exist before other resources. For example, you need a logical SQL server before deploying a database. You establish this relationship by marking one resource as dependent on the other resource. Order of resource deployment can be influenced in two ways: [implicit dependency](#implicit-dependency) and [explicit dependency](#explicit-dependency)
193-
194-
Azure Resource Manager evaluates the dependencies between resources, and deploys them in their dependent order. When resources aren't dependent on each other, Resource Manager deploys them in parallel. You only need to define dependencies for resources that are deployed in the same Bicep file.
195-
196-
### Implicit dependency
197-
198-
An implicit dependency is created when one resource declaration references another resource in the same deployment. For example, *dnsZone* is referenced by the second resource definition in the following example:
199-
200-
```bicep
201-
resource dnsZone 'Microsoft.Network/dnszones@2018-05-01' = {
202-
name: 'myZone'
203-
location: 'global'
204-
}
205-
206-
resource otherResource 'Microsoft.Example/examples@2020-06-01' = {
207-
name: 'exampleResource'
208-
properties: {
209-
// get read-only DNS zone property
210-
nameServers: dnsZone.properties.nameServers
211-
}
212-
}
213-
```
214-
215-
A nested resource also has an implicit dependency on its containing resource.
216-
217-
```bicep
218-
resource myParent 'My.Rp/parentType@2020-01-01' = {
219-
name: 'myParent'
220-
location: 'West US'
221-
222-
// depends on 'myParent' implicitly
223-
resource myChild 'childType' = {
224-
name: 'myChild'
225-
}
226-
}
227-
```
228-
229-
When an implicit dependency exists, **don't add an explicit dependency**.
230-
231-
For more information about nested resources, see [Set name and type for child resources in Bicep](./child-resource-name-type.md).
232-
233-
### Explicit dependency
234-
235-
An explicit dependency is declared with the `dependsOn` property. The property accepts an array of resource identifiers, so you can specify more than one dependency.
236-
237-
The following example shows a DNS zone named `otherZone` that depends on a DNS zone named `dnsZone`:
238-
239-
```bicep
240-
resource dnsZone 'Microsoft.Network/dnszones@2018-05-01' = {
241-
name: 'demoeZone1'
242-
location: 'global'
243-
}
244-
245-
resource otherZone 'Microsoft.Network/dnszones@2018-05-01' = {
246-
name: 'demoZone2'
247-
location: 'global'
248-
dependsOn: [
249-
dnsZone
250-
]
251-
}
252-
```
253-
254-
While you may be inclined to use `dependsOn` to map relationships between your resources, it's important to understand why you're doing it. For example, to document how resources are interconnected, `dependsOn` isn't the right approach. You can't query which resources were defined in the `dependsOn` element after deployment. Setting unnecessary dependencies slows deployment time because Resource Manager can't deploy those resources in parallel.
255-
256-
Even though explicit dependencies are sometimes required, the need for them is rare. In most cases, you can use a symbolic name to imply the dependency between resources. If you find yourself setting explicit dependencies, you should consider if there's a way to remove it.
257-
258-
### Visualize dependencies
259-
260-
Visual Studio Code provides a tool for visualizing the dependencies. Open a Bicep file in Visual Studio Code, and then select the visualizer button on the upper left corner. The following screenshot shows the dependencies of a virtual machine.
261-
262-
:::image type="content" source="./media/resource-declaration/bicep-resource-visualizer.png" alt-text="Screenshot of Visual Studio Code Bicep resource visualizer":::
263-
264-
## Existing resources
265-
266-
To reference a resource that's outside of the current Bicep file, use the `existing` keyword in a resource declaration.
267-
268-
When using the `existing` keyword, provide the `name` of the resource. The following example gets an existing storage account in the same resource group as the current deployment.
269-
270-
```bicep
271-
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
272-
name: 'examplestorage'
273-
}
274-
275-
output blobEndpoint string = stg.properties.primaryEndpoints.blob
276-
```
277-
278-
Optionally, you can set the `scope` property to access a resource in a different scope. The following example references an existing storage account in a different resource group.
279-
280-
```bicep
281-
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
282-
name: 'examplestorage'
283-
scope: resourceGroup(exampleRG)
284-
}
285-
286-
output blobEndpoint string = stg.properties.primaryEndpoints.blob
287-
```
288-
289-
If you attempt to reference a resource that doesn't exist, you get the `NotFound` error and your deployment fails.
290-
291-
For more information about setting the scope, see [Scope functions for Bicep](bicep-functions-scope.md).
292-
293-
The preceding examples don't deploy the storage account. Instead, you can access properties on the existing resource by using the symbolic name.
294-
295188
## Next steps
296189

297190
- To conditionally deploy a resource, see [Conditional deployment in Bicep](./conditional-resource-deployment.md).
191+
- To reference an existing resource, see [Existing resources in Bicep](existing-resource.md).
192+
- To learn about how deployment order is determined, see [Resource dependencies in Bicep](resource-dependencies.md).

articles/azure-resource-manager/bicep/resource-dependencies.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
---
22
title: Set resource dependencies in Bicep
33
description: Describes how to specify the order resources are deployed.
4-
author: mumian
5-
ms.author: jgao
64
ms.topic: conceptual
7-
ms.date: 02/03/2022
5+
ms.date: 02/04/2022
86
---
97

108
# Resource dependencies in Bicep
119

12-
When deploying resources, you may need to make sure some resources exist before other resources. For example, you need a logical SQL server before deploying a database. You establish this relationship by marking one resource as dependent on the other resource. Order of resource deployment can be influenced in two ways: [implicit dependency](#implicit-dependency) and [explicit dependency](#explicit-dependency)
10+
When deploying resources, you may need to make sure some resources are deployed before other resources. For example, you need a logical SQL server before deploying a database. You establish this relationship by marking one resource as dependent on the other resource. The order of resource deployment is determined in two ways: [implicit dependency](#implicit-dependency) and [explicit dependency](#explicit-dependency)
1311

1412
Azure Resource Manager evaluates the dependencies between resources, and deploys them in their dependent order. When resources aren't dependent on each other, Resource Manager deploys them in parallel. You only need to define dependencies for resources that are deployed in the same Bicep file.
1513

1614
## Implicit dependency
1715

18-
An implicit dependency is created when one resource declaration references another resource in the same deployment. For example, *dnsZone* is referenced by the second resource definition in the following example:
16+
An implicit dependency is created when one resource declaration references another resource in the same deployment. In the following example, `otherResource` gets a property from `exampleDnsZone`. The resource named `otherResource` is implicitly dependent on `exampleDnsZone`.
1917

2018
```bicep
21-
resource dnsZone 'Microsoft.Network/dnszones@2018-05-01' = {
19+
resource exampleDnsZone 'Microsoft.Network/dnszones@2018-05-01' = {
2220
name: 'myZone'
2321
location: 'global'
2422
}
@@ -27,7 +25,7 @@ resource otherResource 'Microsoft.Example/examples@2020-06-01' = {
2725
name: 'exampleResource'
2826
properties: {
2927
// get read-only DNS zone property
30-
nameServers: dnsZone.properties.nameServers
28+
nameServers: exampleDnsZone.properties.nameServers
3129
}
3230
}
3331
```
@@ -39,7 +37,7 @@ resource myParent 'My.Rp/parentType@2020-01-01' = {
3937
name: 'myParent'
4038
location: 'West US'
4139
42-
// depends on 'myParent' implicitly
40+
// implicit dependency on 'myParent'
4341
resource myChild 'childType' = {
4442
name: 'myChild'
4543
}
@@ -77,10 +75,10 @@ Even though explicit dependencies are sometimes required, the need for them is r
7775

7876
## Visualize dependencies
7977

80-
Visual Studio Code provides a tool for visualizing the dependencies. Open a Bicep file in Visual Studio Code, and then select the visualizer button on the upper left corner. The following screenshot shows the dependencies of a virtual machine.
78+
Visual Studio Code provides a tool for visualizing the dependencies. Open a Bicep file in Visual Studio Code, and select the visualizer button on the upper left corner. The following screenshot shows the dependencies of a virtual machine.
8179

82-
:::image type="content" source="./media/resource-declaration/bicep-resource-visualizer.png" alt-text="Screenshot of Visual Studio Code Bicep resource visualizer":::
80+
:::image type="content" source="./media/resource-dependencies/bicep-resource-visualizer.png" alt-text="Screenshot of Visual Studio Code Bicep resource visualizer":::
8381

8482
## Next steps
8583

86-
- To conditionally deploy a resource, see [Conditional deployment in Bicep](./conditional-resource-deployment.md).
84+
For the syntax to deploy a resource, see [Resource declaration in Bicep](resource-declaration.md).

0 commit comments

Comments
 (0)