Add Additional Subnets to Virtual Network Without Affecting its Existing Config

Taranjeet Malik 566 Reputation points
2024-04-29T04:46:23.03+00:00

Hi

I'm in a situation where I need to add additional subnets and NSG config to those subnets for an existing Virtual Network using Bicep. The existing Virtual Network and its subnet configuration was deployed in the past using mixed methods (ClickOps and some JSON ARM templates). My question is, can I reference the existing Virtual Network using the "existing" clause in Bicep and try to add new subnets to it without affecting / overwriting the existing subnets?

If not, what are my options in this case?

Thanks

Taranjeet Singh

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,752 questions
0 comments No comments
{count} votes

Accepted answer
  1. KapilAnanth-MSFT 49,521 Reputation points Microsoft Employee Moderator
    2024-04-29T05:28:04.4+00:00

    @Taranjeet Malik ,

    Welcome to the Microsoft Q&A Platform. Thank you for reaching out & I hope you are doing well.

    I understand that you would like to deploy a subnet to an existing VNET using Bicep without disrupting the existing subnet configurations.

    Yes, this is doable.

    You can use the below bicep configuration example to achieve this.

    var subnetName = 'newSubnet'
    var vnetName = 'vnet'
    
    resource myvnet 'Microsoft.Network/virtualNetworks@2023-04-01' existing = {
      name: vnetName
    }
    
    resource subnet 'Microsoft.Network/virtualNetworks/subnets@2023-04-01' = {
    
      name: subnetName
      parent: myvnet
      properties:{
        addressPrefix:'10.0.20.0/24' //Address prefix should **not** be overlapping with existing subnets
      }
    
    }
    
    

    Thanks,

    Kapil


    Please Accept an answer if correct.

    Original posters help the community find answers faster by identifying the correct answer.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.