首页 > 解决方案 > 无法创建新的 Nutanix VM 并将其分配给项目

问题描述

我正在尝试使用 terraform v0.15.0 在 Nutanix 上创建一台新机器,并将该机器分配给我已经拥有的现有项目(在没有 terraform 的 UI 上创建)。
使用 Nutanix 文档(https://registry.terraform.io/providers/nutanix/nutanix/latest/docs/resources/virtual_machine#project_reference),我能够创建一个 VM,但不能将其分配给现有项目。使用此 main.tf 有效,但是,取消注释该project_reference属性会导致以下错误:

nutanix_virtual_machine.vm1[0]: Creating...
    
Error: error: {
    "api_version": "3.1",
    "code": 422,
    "message_list": [
    {
        "details": {
            "metadata": [
                "Additional properties are not allowed (u'project_reference' was unexpected)"
            ]
        },
        "message": "Request could not be processed.",
        "reason": "INVALID_REQUEST"
    }
    ],
    "state": "ERROR"
}
    
     
    
on main.tf line 67, in resource "nutanix_virtual_machine" "vm1":
67: resource "nutanix_virtual_machine" "vm1" {
    
  

这是我的代码:

provider "nutanix" {
    username     = "user"
    password     = "pass"
    port         = 1234
    endpoint     = "ip"
    insecure     = true
    wait_timeout = 10 
}

data "nutanix_cluster" "cluster" {
    name = "NTNXCluster" 
}

data "nutanix_image" "ubuntu-clone" {
    image_name = "Ubuntu-20.04-Server"
}

variable "counter" {
    type = number
    default = 1
}

resource "nutanix_virtual_machine" "vm1" {

    name                 = "test-${count.index+1}"
    count                = var.counter
    description          = "desc"
    num_vcpus_per_socket = 2
    num_sockets          = 2
    memory_size_mib      = 4096
    guest_customization_sysprep = {}
    cluster_uuid = "my_uuid"
    nic_list {
        subnet_uuid = "my_uuid"
    }

    #project_reference = {
    # kind = "project"
    # uuid = "my_uuid"
    # name = "my_project"
    #}
  
    disk_list {
        data_source_reference = {
            kind = "image"
            uuid = data.nutanix_image.ubuntu-clone.id
        }
        device_properties {
            disk_address = {
                device_index = 0
                adapter_type = "SATA"
            }
        device_type = "DISK"
    }
    }
}

标签: terraform

解决方案


在 Nutanix 支持要求我debug在 terraform 中使用模式后,我发现了问题。

在调试模式下,我看到 terraform 正在使用无法在Nutanix Elements.

只能从 中创建带有项目Nutanix Prism的 VM ,而我使用了Nutanix Elements提供程序。

使用相同的 terraform将提供程序从 切换Nutanix Elements到,按预期工作。Nutanix Prismmain.yml


推荐阅读