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
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/scenarios-virtual-networks.md
+14-29Lines changed: 14 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Create virtual network resources by using Bicep
3
3
description: Describes how to create virtual networks, network security groups, and route tables by using Bicep.
4
4
ms.topic: conceptual
5
5
ms.custom: devx-track-bicep
6
-
ms.date: 03/17/2025
6
+
ms.date: 04/02/2025
7
7
---
8
8
9
9
# Create virtual network resources by using Bicep
@@ -16,14 +16,12 @@ Define your virtual networks by creating a resource with the type [`Microsoft.Ne
16
16
17
17
### Configure subnets by using the subnets property
18
18
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.
20
20
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).
23
23
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:
27
25
28
26
```bicep
29
27
param location string = resourceGroup().location
@@ -32,7 +30,7 @@ var virtualNetworkName = 'my-vnet'
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
-
77
62
### Access subnet resource IDs
78
63
79
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:
0 commit comments