代码之家  ›  专栏  ›  技术社区  ›  Jaish Mathews

为什么我不能用TerraForm平滑地创建Azure虚拟机?

  •  0
  • Jaish Mathews  · 技术社区  · 6 年前

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

    azurerm_virtual_machine.vm:仍在创建…(已过17m3) 释放状态锁。这可能需要一些时间…

    错误:应用计划时出错:

    发生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
      }
    }
    1 回复  |  直到 6 年前
        1
  •  1
  •   Charles Xu    6 年前

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

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

    第二,您的虚拟机太小,因此创建虚拟机需要很长时间。如果你换大一点的尺寸,时间就会缩短。

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