簡體   English   中英

如何使用 ARM 或 Azure CLI 將現有的 virtual.netwrok 連接到開發測試實驗室?

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

我有一個資源組,其中包含使用 Bicep 單獨創建的開發測試實驗室和虛擬網絡 (VNet)。

我可以使用 Azure 門戶手動將 VNet 附加到開發測試實驗室:

  1. Go 至開發測試實驗室
  2. Select "配置和策略"
  3. 從外部資源菜單中,select“Virtual.networks”
  4. 點擊“添加”
  5. Select 越網

是否可以使用 Azure CLI 自動執行此過程? 或任何其他選擇?

由於我正在采用 Azure DevOps 管道來自動運行(Bicep 代碼)和調整(Azure CLI)資源。

我正在為 .NET 使用 ARM/Bicep 模板 ( Microsoft.Network/virtualNetworks@2021-02-01 ),為開發測試實驗室使用 ( Microsoft.DevTestLab/labs@2018-09-15 )

如果您要分別創建 .net 和 Devtest 實驗室,那么您可以使用來自 Github 的以下Azure 快速入門模板來創建具有現有 .net 的 Devtestlab:

JSON ARM:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "newLabName": {
        "type": "string",
        "metadata": {
          "description": "The name of the new lab instance to be created."
        }
      },
      "newLabVirtualNetworkName": {
        "type": "string",
        "metadata": {
          "description": "The name of the new lab virtual network instance to be created with the new lab instance being created."
        }
      },
      "existingVirtualNetworkId": {
        "type": "string",
        "metadata": {
          "description": "The resource ID pointing to an existing (compute) virtual network to be referenced by the new lab virtual network instance being created."
        }
      },
      "existingSubnetName": {
        "type": "string",
        "defaultValue": "default",
        "metadata": {
          "description": "The name of an existing (compute) subnet instance to be configured for Lab VM creation."
        }
      }
    },
    "variables": {
      "existingSubnetId": "[concat(parameters('existingVirtualNetworkId'), '/subnets/', parameters('existingSubnetName'))]"
    },
    "resources": [
      {
        "apiVersion": "2018-10-15-preview",
        "type": "Microsoft.DevTestLab/labs",
        "name": "[parameters('newLabName')]",
        "location": "[resourceGroup().location]",
        "resources": [
          {
            "apiVersion": "2018-10-15-preview",
            "name": "[parameters('newLabVirtualNetworkName')]",
            "type": "virtualNetworks",
            "dependsOn": [
              "[resourceId('Microsoft.DevTestLab/labs', parameters('newLabName'))]"
            ],
            "properties": {
              "description": "Existing Compute virtual network associated as part of the lab creation process.",
              "externalProviderResourceId": "[parameters('existingVirtualNetworkId')]",
              "subnetOverrides": [
                {
                  "name": "[parameters('existingSubnetName')]",
                  "resourceId": "[variables('existingSubnetId')]",
                  "useInVmCreationPermission": "Allow",
                  "usePublicIpAddressPermission": "Allow"
                }
              ]
            }
          }
        ]
      }
    ],
    "outputs": {
      "labId": {
        "type": "string",
        "value": "[resourceId('Microsoft.DevTestLab/labs', parameters('newLabName'))]"
      }
    }
  }

輸出:我在我的環境中測試了它,結果如下:

在此處輸入圖像描述

在此處輸入圖像描述

在此處輸入圖像描述

在此處輸入圖像描述

注意:不幸的是,沒有使用Azure CLIAzure-Powershell連接 .net 和Devtestlabs的命令。

二頭肌 ARM:

@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

輸出:

在此處輸入圖像描述

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM