Skip to content

Commit 0adbd24

Browse files
committed
update vnet subnet info
1 parent 5fe6610 commit 0adbd24

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

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

Lines changed: 14 additions & 29 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: 03/17/2025
6+
ms.date: 04/02/2025
77
---
88

99
# Create virtual network resources by using Bicep
@@ -16,14 +16,12 @@ Define your virtual networks by creating a resource with the type [`Microsoft.Ne
1616

1717
### Configure subnets by using the subnets property
1818

19-
Virtual networks contain subnets, which are logical groups of IP addresses within the virtual network. There are two ways to define subnets in Bicep: by using the `subnets` property on the virtual network resource, and by creating a [child resource](child-resource-name-type.md) with type `Microsoft.Network/virtualNetworks/subnets`.
19+
Virtual networks contain subnets, which are logical groupings of IP addresses within the network. Subnets should always be managed as child resources, and the **subnets** property should never be defined within the virtual network resource. This approach ensures a safe and independent lifecycle for both resource types.
2020

21-
> [!WARNING]
22-
> Avoid defining subnets as child resources. This approach can result in downtime for your resources during subsequent deployments, or failed deployments.
21+
> [!NOTE]
22+
> Microsoft has updated the Azure Virtual Network API 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 is not included in a PUT request, the existing subnets remain unchanged. Explicitly setting the subnet property to an empty value will delete all existing subnets, while providing specific subnet configurations will update or create 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 within the virtual network definition, as in this example:
25-
26-
> 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).
24+
It's best to define your subnets as child resources, as in this example:
2725

2826
```bicep
2927
param location string = resourceGroup().location
@@ -32,7 +30,7 @@ var virtualNetworkName = 'my-vnet'
3230
var subnet1Name = 'Subnet-1'
3331
var subnet2Name = 'Subnet-2'
3432
35-
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2023-11-01' = {
33+
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2024-05-01' = {
3634
name: virtualNetworkName
3735
location: location
3836
properties: {
@@ -41,39 +39,26 @@ resource virtualNetwork 'Microsoft.Network/virtualNetworks@2023-11-01' = {
4139
'10.0.0.0/16'
4240
]
4341
}
44-
subnets: [
45-
{
46-
name: subnet1Name
47-
properties: {
48-
addressPrefix: '10.0.0.0/24'
49-
}
50-
}
51-
{
52-
name: subnet2Name
53-
properties: {
54-
addressPrefix: '10.0.1.0/24'
55-
}
56-
}
57-
]
5842
}
5943
60-
resource subnet1 'subnets' existing = {
44+
resource subnet1 'subnets' = {
6145
name: subnet1Name
62-
}
46+
properties: {
47+
addressPrefix: '10.0.0.0/24'
48+
} }
6349
64-
resource subnet2 'subnets' existing = {
50+
resource subnet2 'subnets' = {
6551
name: subnet2Name
52+
properties: {
53+
addressPrefix: '10.0.1.0/24'
54+
}
6655
}
6756
}
6857
6958
output subnet1ResourceId string = virtualNetwork::subnet1.id
7059
output subnet2ResourceId string = virtualNetwork::subnet2.id
7160
```
7261

73-
Although both approaches enable you to define and create your subnets, there is an important difference. When you define subnets by using child resources, the first time your Bicep file is deployed, the virtual network is deployed. Then, after the virtual network deployment is complete, each subnet is deployed. This sequencing occurs because Azure Resource Manager deploys each individual resource separately.
74-
75-
When you redeploy the same Bicep file, the same deployment sequence occurs. However, the virtual network is deployed without any subnets configured on it because the `subnets` property is effectively empty. Then, after the virtual network is reconfigured, the subnet resources are redeployed, which re-establishes each subnet. In some situations, this behavior causes the resources within your virtual network to lose connectivity during your deployment. In other situations, Azure prevents you from modifying the virtual network and your deployment fails.
76-
7762
### Access subnet resource IDs
7863

7964
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:

0 commit comments

Comments
 (0)