Skip to content

Commit 46e653a

Browse files
committed
update referencing subnet id
1 parent 04b48d8 commit 46e653a

File tree

1 file changed

+3
-57
lines changed

1 file changed

+3
-57
lines changed

articles/azure-resource-manager/bicep/scenarios-virtual-networks.md

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Create virtual network resources by using Bicep
33
description: Describes how to create virtual networks, network security groups, and route tables by using Bicep.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 04/02/2025
6+
ms.date: 04/25/2025
77
---
88

99
# Create virtual network resources by using Bicep
@@ -21,7 +21,7 @@ Virtual networks contain subnets, which are logical groupings of IP addresses wi
2121
> [!NOTE]
2222
> The Azure Virtual Network API is updated to allow modifications to virtual networks without requiring the inclusion of the subnet property in PUT requests. Previously, omitting the subnet property would result in the deletion of existing subnets. With the new behavior, if the subnet property isn't included in a PUT request, the existing subnets remain unchanged. Explicitly setting the subnet property to an empty value deletes all existing subnets, while providing specific subnet configurations creates or updates subnets accordingly. This change simplifies virtual network management by preventing unintended subnet deletions during updates. For more information, see [Azure Virtual Network now supports updates without subnet property](https://techcommunity.microsoft.com/blog/azurenetworkingblog/azure-virtual-network-now-supports-updates-without-subnet-property/4067952).
2323
24-
It's best to define your subnets as child resources, as in this example:
24+
It's best to define your subnets as [child resources](./child-resource-name-type.md#within-parent-resource), as in this example:
2525

2626
```bicep
2727
param location string = resourceGroup().location
@@ -59,60 +59,7 @@ output subnet1ResourceId string = virtualNetwork::subnet1.id
5959
output subnet2ResourceId string = virtualNetwork::subnet2.id
6060
```
6161

62-
### Access subnet resource IDs
63-
64-
You often need to refer to a subnet's resource ID. When you use the `subnets` property to define your subnet, [you can use the `existing` keyword](existing-resource.md) to also obtain a strongly typed reference to the subnet, and then access the subnet's `id` property:
65-
66-
> The following example is part of a larger example. For a Bicep file that you can deploy, [see the complete file](https://raw.githubusercontent.com/Azure/azure-docs-bicep-samples/main/samples/scenarios-virtual-networks/vnet.bicep).
67-
68-
```bicep
69-
param location string = resourceGroup().location
70-
71-
var virtualNetworkName = 'my-vnet'
72-
var subnet1Name = 'Subnet-1'
73-
var subnet2Name = 'Subnet-2'
74-
75-
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2023-11-01' = {
76-
name: virtualNetworkName
77-
location: location
78-
properties: {
79-
addressSpace: {
80-
addressPrefixes: [
81-
'10.0.0.0/16'
82-
]
83-
}
84-
subnets: [
85-
{
86-
name: subnet1Name
87-
properties: {
88-
addressPrefix: '10.0.0.0/24'
89-
}
90-
}
91-
{
92-
name: subnet2Name
93-
properties: {
94-
addressPrefix: '10.0.1.0/24'
95-
}
96-
}
97-
]
98-
}
99-
100-
resource subnet1 'subnets' existing = {
101-
name: subnet1Name
102-
}
103-
104-
resource subnet2 'subnets' existing = {
105-
name: subnet2Name
106-
}
107-
}
108-
109-
output subnet1ResourceId string = virtualNetwork::subnet1.id
110-
output subnet2ResourceId string = virtualNetwork::subnet2.id
111-
```
112-
113-
Because this example uses the `existing` keyword to access the subnet resource, instead of defining the complete subnet resource, it doesn't have the risks outlined in the previous section.
114-
115-
You can also combine the `existing` and `scope` keywords to refer to a virtual network or subnet resource in another resource group.
62+
To reference a nested resource outside the parent resource, it must be qualified with the containing resource name and the :: operator as shown in the preceding exeample.
11663

11764
## Network security groups
11865

@@ -133,4 +80,3 @@ Private endpoint approval is an operation, so you can't perform it directly with
13380
- Quickstart templates
13481
- [Create a Virtual Network with two Subnets](https://azure.microsoft.com/resources/templates/vnet-two-subnets/)
13582
- [Virtual Network with diagnostic logs](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/vnet-create-with-diagnostic-logs)
136-

0 commit comments

Comments
 (0)