一段时间以来,我一直在使用 Terraform 在 Azure 上部署 VM。它一直运行良好,但今天我发现尝试部署 vnet 时它会在 10 分钟后超时,这是以前从未发生过的。这是日志:
Error: Error applying plan:
1 error(s) occurred:
* azurerm_virtual_network.vnet: 1 error(s) occurred:
* azurerm_virtual_network.vnet: network.VirtualNetworksClient#CreateOrUpdate: Failure sending request: StatusCode=200 -- Original Error: Long running operation terminated with status 'Failed': Code="InternalServerError" Message="An error occurred."
我一开始以为是 Terraform 或azurerm
插件错误,所以我尝试了几种组合(terraform 0.11.3/azurerm 1.1.1、terraform 0.10.6/azurerm 0.3.3 等)。我对他们所有人都有同样的问题。我可以毫无问题地从 Azure 门户创建 VM,所以我猜问题出在 Terraform 或 Azure API Terraform 正在后台使用。无论如何,我不知道如何调试它。
这是我正在使用的 terraform 模板:
# Configure Azure provider
provider "azurerm" {
subscription_id = "..."
client_id = "..."
client_secret = "..."
tenant_id = "..."
}
# create a resource group if it doesn't exist
resource "azurerm_resource_group" "rg" {
name = "a132rg"
location = "ukwest"
}
# 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}"
}
# create subnet
resource "azurerm_subnet" "subnet" {
name = "tfsub"
resource_group_name = "${azurerm_resource_group.rg.name}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
address_prefix = "10.0.2.0/24"
#network_security_group_id = "${azurerm_network_security_group.nsg.id}"
}
# create public IPs
resource "azurerm_public_ip" "ip" {
name = "tfip"
location = "ukwest"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "dynamic"
domain_name_label = "a132"
tags {
environment = "staging"
}
}
# create network interface
resource "azurerm_network_interface" "ni" {
name = "tfni"
location = "ukwest"
resource_group_name = "${azurerm_resource_group.rg.name}"
ip_configuration {
name = "ipconfiguration"
subnet_id = "${azurerm_subnet.subnet.id}"
private_ip_address_allocation = "static"
private_ip_address = "10.0.2.5"
public_ip_address_id = "${azurerm_public_ip.ip.id}"
}
}
# create storage account
resource "azurerm_storage_account" "storage" {
name = "0fda935368315bd1a5f5560e"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "ukwest"
account_replication_type = "LRS"
account_tier = "Standard"
tags {
environment = "staging"
}
}
# create storage container
resource "azurerm_storage_container" "storagecont" {
name = "vhd"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_name = "${azurerm_storage_account.storage.name}"
container_access_type = "private"
depends_on = ["azurerm_storage_account.storage"]
}
# create virtual machine
resource "azurerm_virtual_machine" "vm" {
name = "a132vm"
location = "ukwest"
resource_group_name = "${azurerm_resource_group.rg.name}"
network_interface_ids = ["${azurerm_network_interface.ni.id}"]
vm_size = "Standard_A6"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk"
vhd_uri = "${azurerm_storage_account.storage.primary_blob_endpoint}${azurerm_storage_container.storagecont.name}/myosdisk.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "a132"
admin_username = "..."
admin_password = "..."
}
}