【问题标题】:Virtual Machine from Azure marketplace image with terraform script having an errorAzure 市场映像中的虚拟机,带有错误的 terraform 脚本
【发布时间】:2021-06-15 12:32:15
【问题描述】:

我是 Azure 新手。我正在使用 terraform 从市场映像部署 Azure 虚拟机。 我已经编写了代码,但出现错误。

  resource "azurerm_virtual_machine" "virtualmachine" {
  name                  = "virtualmachine01"
  location              = "centralus"
  resource_group_name   = "xyz"
  network_interface_ids = [azurerm_network_interface.nics.id]
  vm_size               = "Standard_F2"

source_image_reference {
    publisher = "cloudeteer"
    offer     = "cdt_cloud-ops"
    plan       = "cloud_pro"
    version   = "latest"
  }

 tags = module.tags.tags_output
# Creating a Virtual network interface 
esource "azurerm_network_interface" "nics01" {
   name                        = "nicsexample"
   location                    = var.location
   resource_group_name         = "rg"
   tags                        = module.tags.tags_output
   ip_configuration {
       name                          = "ipconfigexample"
       subnet_id                     = "id"
       private_ip_address_allocation = "static"
       private_ip_address            = var.vm1_private_ip_address
       
   }
}
}

错误:不支持的块类型

在 virtual_machine.tf 第 21 行,资源“azurerm_virtual_machine”“virtualmachine”中: 21: source_image_reference {

此处不应出现“source_image_reference”类型的块。

谁能帮忙。

【问题讨论】:

    标签: azure terraform


    【解决方案1】:

    source_image_referenceazurerm_linux_virtual_machine 的一部分,而不是azurerm_virtual_machine

    因此您必须更改virtualmachine资源类型,如果它们之间存在差异,则可能调整其他属性。

    【讨论】:

      【解决方案2】:

      没错,source_image_reference 是 azurerm_linux_virtual_machine 的一部分,而不是 azurerm_virtual_machine。所以你必须改变属性。

      这取决于您使用的市场类型。如果是windows相关的,可以使用“Storage image reference”,下面不需要plan id,否则会报错。您可以添加 SKU 详细信息并尝试创建

      source_image_reference {
        publisher = "cloudeteer"
        offer     = "cdt_cloud-ops"
        sku       = "cloud_pro"
        version   = "latest"
      

      }

      同时添加计划块

      plan{
        name = "cloude"
        product = "cloudeteer"
        publisher = "cloudeteer"
      }
      

      其余代码对我来说看起来不错。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-13
        • 1970-01-01
        • 1970-01-01
        • 2021-07-11
        • 2016-05-10
        • 2022-12-21
        • 2014-06-13
        • 2022-10-15
        相关资源
        最近更新 更多