setazurearmvmnic

從開始用 Microsoft Azure 以來,一直堅持龜毛的事情是,任何的資源名稱都盡可能有規則,因為這讓我在管理及使用上有較佳的體驗;儘管 Azure 去年底正式發佈使用新的入口網站,建立 VM 的過程可以如舊管理平台,不用事先新建與 VM 相關像是虛擬網路、儲存體等資源,但建出來的名稱就是如下圖的混亂。
setazurearmvmnic01

同樣的名稱其實是不同的資源類型。
setazurearmvmnic02

但認真準備的話,新管理平台是可以讓你先新增會用到的資源,再於建立 VM 過程代入對應所需資源,就不會有名稱混亂的問題。
setazurearmvmnic05

目前,尚無法在建立 VM 過程自訂帶入的,則是 VM 網路介面資源。所以怎樣建立全新的 VM,都一定會有一個帶亂數的網路介面資源名稱。
setazurearmvmnic04

而且,即便關閉 VM,也無法從網站上直接變更網路介面資源。

花時間研究了一下,還好那句老話依舊有用:「GUI 有限,指令無限

請先安裝 Azure CLI,接著開啟命令提示字元或 PowerShell,依序參照下面 Azure CLI 指令及訊息,登入 Azure 及選擇對應的訂閱進行管理。

azure login
azure account set "訂閱名稱或ID"

setazurearmvmnic03

最後,只要執行下面指令就能完成變更了。因此,那個看不順眼的網路介面資源名稱,在中斷相關資源的連結後,也就能輕鬆送他上路。

azure vm set "VM 所屬資源群組名稱" "VM 名稱" -N "欲變更的網路介面資源名稱"

setazurearmvmnic06

如果在變更 Azure VM 的網路介面資源,發生如下的錯誤,其中提到:
ipconfig1 is not in the same Virtual Network as the subnets of other VMs in the availability set.

+ Updating VM "azurevm"
error:   Subnet VNet10 referenced by resource /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/azure-rsgp/providers/Microsoft.Network/networkInterfaces/azure-nic/ipConfigurations/ipconfig1 is not in the same Virtual Network as the subnets of other VMs in the availability set.
info:    Error information has been recorded to C:\Users\Aska\.azure\azure.err
error:   vm set command failed

setazurearmvmnic_error

請到網路介面資源的管理平台,檢查及確認欲變更的網路介面,是否與原 VM 使用的網路介面位於相同的虛擬網路資源

用下圖來解釋
亂數名的網路介面、NIC1 及 NIC2 都位於 VNet 的資源中,所以這三個網路介面可以任意變更;但 NIC3 卻是位於另一個名為 VNet2 網路資源,因此 VM 無法變更使用 NIC3。
setazurearmvmnic07

那這問題有沒有解?花了點研究及測試....嗯...在微軟官方部落格的這篇文章 - How to change Subnet and Virtual Network for Azure Virtual Machines (ASM & ARM),「Change Virtual Network in ASM and ARM」一節提到:「Unfortunately, today is not possible/supported to change directly a VNET for an existing VM. the only way to operate this change is export the VM definition, drop the VM preserving disks, then re-create the VM with the same settings, except for the new VNET assignment, and attaching previous disks.

簡單幫大家翻譯,遇到上面的狀況,目前就是只能請您砍掉重練... /=.=/