我尝试将现有的网卡连接到虚拟机,同时使用azure bicep重新部署。它不会附加旧的网卡并创建新的网卡并将其附加到虚拟机。请帮助如何解决此问题。预先感谢
请提供示例代码来解决此问题。
使用 azure bicep 将现有 NIC 添加到新虚拟机。
在部署虚拟机 (VM) 期间连接网络接口卡 (NIC),而不是创建新的网络接口卡,您可以按照以下步骤操作来确保您的 Bicep 模板
vm-deployment.bicep:
resource existingNic 'Microsoft.Network/networkInterfaces@2021-05-01' existing = {
name: 'vinay-nic'
// Add 'scope' if the NIC is in a different resource group
// scope: resourceGroup('otherResourceGroupName')
}
resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-07-01' = {
name: 'vinay-vm'
location: resourceGroup().location
properties: {
hardwareProfile: {
vmSize: 'Standard_D2s_v3' // Adjust the size as needed
}
storageProfile: {
imageReference: {
publisher: 'Canonical'
offer: 'UbuntuServer'
sku: '18.04-LTS'
version: 'latest'
}
osDisk: {
createOption: 'FromImage'
managedDisk: {
storageAccountType: 'Premium_LRS'
}
}
}
osProfile: {
computerName: 'vinay-vm'
adminUsername: 'adminuser'
adminPassword: 'yourpassword'
}
networkProfile: {
networkInterfaces: [
{
id: existingNic.id
properties: {
primary: true
}
}
]
}
}
}
现在运行下面的命令
az deployment group create --resource-group vinay-rg --template-file {path}/vm-deployment.bicep
部署成功: