How to connect an existing virtual netwrok to DevTest lab using ARM or Azure CLI?

Ahmed Madhun 72 Reputation points
2021-09-26T15:36:38.51+00:00

I have a resource group that contains separately created DevTest lab and Virtual Network (VNet) using Bicep.

I can manually by using the Azure portal attach the VNet to the Devtest lab by:

  1. Go to Devtest lab
  2. Select "Configuration and policies"
  3. From the External resources menu, select "Virtual networks"
  4. Click "Add"
  5. Select the VNet

Is it possible to automate this process using Azure CLI? or any other alternative?

As I am adopting Azure DevOps pipelines to run (Bicep code) and adjust (Azure CLI) the resources automatically.

I am using ARM/Bicep template (Microsoft.Network/virtualNetworks@2021-02-01) for VNET, and (Microsoft.DevTestLab/labs@2018-09-15) for DevTest lab

Azure DevTest Labs
Azure DevTest Labs
An Azure service that is used for provisioning development and test environments.
291 questions
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,772 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. suvasara-MSFT 10,076 Reputation points Moderator
    2021-09-27T13:10:35.977+00:00

    @Anonymous , Here is an ARM template that creates a new DevTest Lab / DTL instance that leverages an existing virtual network. You should be able to quickly convert this deploy. Json file to bicep using this bicep playground.

    @description('The name of the new lab instance to be created.')  
    param newLabName string  
      
    @description('The name of the new lab virtual network instance to be created with the new lab instance being created.')  
    param newLabVirtualNetworkName string  
      
    @description('The resource ID pointing to an existing (compute) virtual network to be referenced by the new lab virtual network instance being created.')  
    param existingVirtualNetworkId string  
      
    @description('The name of an existing (compute) subnet instance to be configured for Lab VM creation.')  
    param existingSubnetName string = 'default'  
      
    var existingSubnetId = '${existingVirtualNetworkId}/subnets/${existingSubnetName}'  
      
    resource newLabName_resource 'Microsoft.DevTestLab/labs@2018-10-15-preview' = {  
      name: newLabName  
      location: resourceGroup().location  
    }  
      
    resource newLabName_newLabVirtualNetworkName 'Microsoft.DevTestLab/labs/virtualNetworks@2018-10-15-preview' = {  
      parent: newLabName_resource  
      name: '${newLabVirtualNetworkName}'  
      properties: {  
        description: 'Existing Compute virtual network associated as part of the lab creation process.'  
        externalProviderResourceId: existingVirtualNetworkId  
        subnetOverrides: [  
          {  
            name: existingSubnetName  
            resourceId: existingSubnetId  
            useInVmCreationPermission: 'Allow'  
            usePublicIpAddressPermission: 'Allow'  
          }  
        ]  
      }  
    }  
      
    output labId string = newLabName_resource.id  
    

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    1 person found this answer 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.