0

大约 17 分钟后,我从命令提示符处收到以下错误消息。执行似乎太长了?还是预期的持续时间?

azurerm_virtual_machine.vm:仍在创建...(经过 17 分 30 秒)释放状态锁。这可能需要一些时间...

错误:应用计划时出错:

发生 1 个错误:

  • azurerm_virtual_machine.vm:发生 1 个错误:

  • azurerm_virtual_machine.vm:意外的 EOF

Terraform 不会在遇到错误时自动回滚。相反,您的 Terraform 状态文件已使用成功完成的任何资源进行了部分更新。请解决上述错误并再次申请以逐步更改您的基础架构。

在门户内部检查后,它仍显示“正在创建...”状态。我使用了下面的 .tf 文件。里面有什么问题吗?

provider "azurerm" {}

variable "location" {
  default = "East US"
}

variable "username" {
  default = "..."
}

variable "password" {
  default = "..."
}

resource "azurerm_resource_group" "resourceGroup" {
  name     = "TerraformResearchResourceGroup"
  location = "${var.location}"
}

resource "azurerm_public_ip" "publicip" {
  name                         = "terraformresearchpublicip"
  location                     = "${var.location}"
  resource_group_name          = "${azurerm_resource_group.resourceGroup.name}"
  public_ip_address_allocation = "Dynamic"
  idle_timeout_in_minutes      = 30

  tags {
    environment = "test"
  }
}

resource "azurerm_virtual_network" "vnet" {
  name                = "terraformresearchnetwork"
  address_space       = ["10.0.0.0/16"]
  location            = "${var.location}"
  resource_group_name = "${azurerm_resource_group.resourceGroup.name}"
}

resource "azurerm_subnet" "subnet" {
  name                 = "terraformresearchsubnet"
  resource_group_name  = "${azurerm_resource_group.resourceGroup.name}"
  virtual_network_name = "${azurerm_virtual_network.vnet.name}"
  address_prefix       = "10.0.2.0/24"
}

resource "azurerm_network_interface" "nic" {
  name                = "terraformresearchnic"
  location            = "${var.location}"
  resource_group_name = "${azurerm_resource_group.resourceGroup.name}"

  ip_configuration {
    name                          = "terraformresearchconfiguration"
    subnet_id                     = "${azurerm_subnet.subnet.id}"
    private_ip_address_allocation = "dynamic"
    public_ip_address_id          = "${azurerm_public_ip.publicip.id}"
  }
}

resource "azurerm_storage_account" "storageacc" {
  name                     = "terraformresearchstoacc"
  resource_group_name      = "${azurerm_resource_group.resourceGroup.name}"
  location                 = "${var.location}"
  account_tier             = "Standard"
  account_replication_type = "GRS"
}

resource "azurerm_storage_container" "storagecont" {
  name                  = "terraformresearchstoragecont"
  resource_group_name   = "${azurerm_resource_group.resourceGroup.name}"
  storage_account_name  = "${azurerm_storage_account.storageacc.name}"
  container_access_type = "private"
}

resource "azurerm_managed_disk" "datadisk" {
  name                 = "terraformresearchdatadisk"
  location             = "${var.location}"
  resource_group_name  = "${azurerm_resource_group.resourceGroup.name}"
  storage_account_type = "Standard_LRS"
  create_option        = "Empty"
  disk_size_gb         = "1023"
}

resource "azurerm_virtual_machine" "vm" {
  name                  = "terraformrvm"
  location              = "${var.location}"
  resource_group_name   = "${azurerm_resource_group.resourceGroup.name}"
  network_interface_ids = ["${azurerm_network_interface.nic.id}"]
  vm_size               = "Standard_A0"

  storage_image_reference {
    publisher = "MicrosoftWindowsServer"
    offer     = "WindowsServer"
    sku       = "2016-Datacenter"
    version   = "latest"
  }

  storage_os_disk {
    name              = "terraformresearhosdisk"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }

  storage_data_disk {
    name            = "${azurerm_managed_disk.datadisk.name}"
    managed_disk_id = "${azurerm_managed_disk.datadisk.id}"
    create_option   = "Attach"
    lun             = 1
    disk_size_gb    = "${azurerm_managed_disk.datadisk.disk_size_gb}"
  }

  os_profile {
    computer_name  = "terraformrvm"
    admin_username = "${var.username}"
    admin_password = "${var.password}"
  }

  os_profile_windows_config {
    enable_automatic_upgrades = false
    provision_vm_agent = true
  }
}

4

1 回答 1

1

对于您的问题,我进行了测试,您的 .tf 文件中需要更改一些内容。

首先,存储帐户名称的长度必须小于或等于 20。

其次,你的虚拟机太小,创建虚拟机需要很长时间。如果换成更大的尺寸,时间会缩短。

最后一件事是用户名和密码应该在变量中定义。我想你知道的。

于 2018-07-10T07:44:54.713 回答