Ubuntu

Terraform 無法在 Azure 中創建虛擬網路

  • February 9, 2018

幾天以來,我無法在任何資源組中創建虛擬網路。我收到以下消息

Error: Error applying plan:

1 error(s) occurred:

* azurerm_virtual_network.qmlnetwork: 1 error(s) occurred:

* azurerm_virtual_network.qmlnetwork: Error waiting for completion of Virtual Network "qumulate_network" (Resource Group "QumulateCi"): Long running operation terminated with status 'Failed': Code="InternalServerError" Message="An error occurred."

我試圖更改名稱、IP 範圍。嘗試創建一個全新的資源組。完全乾淨的 terraform 工作區。沒有幫助。這是我的程式碼。

resource "azurerm_virtual_network" "qmlnetwork" {
name        = "${var.network_name}"
address_space   = ["10.4.0.0/24"]
location    = "${azurerm_resource_group.myproductterraform.location}"
resource_group_name = "${azurerm_resource_group.myproductterraform.name}"
}

/* Add subnet */
resource "azurerm_subnet" "qmlsubnet" {
 name                 = "${var.myproduct_subnet}"
 resource_group_name  = "${azurerm_resource_group.myproductterraform.name}"
 virtual_network_name = "${azurerm_virtual_network.qmlnetwork.name}"
 address_prefix       = "10.4.0.0/24"
}

謝謝你的回答,你是對的。創建 VNet 時,需要在其中創建子網。修改 tf 如下:

# create virtual network
resource "azurerm_virtual_network" "vnet" {
   name = "tfvnet"
   address_space = ["10.0.0.0/16"]
   location = "ukwest"
   resource_group_name = "${azurerm_resource_group.rg.name}"
   ##You need create a subnet in VNet.
   subnet {
       name = "subnet1"
       address_prefix = "10.0.3.0/24"

   }
} 

您也可以在官方文件上查看此範例。

某些地區正在持續中斷。根據我們的理解,Terraform 嘗試部署具有空子網定義的 VNET。這是一個有效的操作,因為子網定義不是強制性的 ( https://docs.microsoft.com/en-us/azure/templates/microsoft.network/virtualnetworks#VirtualNetworkPropertiesFormat )

引用自:https://serverfault.com/questions/896307