nutanix / terraform-provider-nutanix

Terraform Nutanix Provider
https://www.terraform.io/docs/providers/nutanix/
Mozilla Public License 2.0
93 stars 112 forks source link

Error Using 'data_source_reference' attribute for 'nutanix_image' resource #652

Open tbeConfo opened 7 months ago

tbeConfo commented 7 months ago

Nutanix Cluster Information

provider "nutanix" { username = var.nutanix_username password = var.nutanix_password endpoint = var.nutanix_endpoint port = var.nutanix_endpoint_port insecure = true wait_timeout = 10 }

resource "nutanix_image" "test" { name = "linux-img--SCSI.0-1" description = "Linux img"

data_source_reference = { kind = "vm_disk" uuid = "b62dbfa7-f19b-440a-938c-e28ea3c98d21" } image_type = "DISK_IMAGE" architecture = "X86_64"

initial_placement_ref_list = [ { kind = "cluster" uuid = "000608ae-3fc3-9376-62f5-0894efbcc894" } ] }

### Debug Output
<!---
Please provide a link to a GitHub Gist containing the complete debug output. Please do NOT paste the debug output in the issue; just paste a link to the Gist.
To obtain the debug output, see the [Terraform documentation on debugging](https://www.terraform.io/docs/internals/debugging.html).
--->
### Panic Output
<!--- If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the `crash.log`. --->
### Expected Behavior
<!--- What should have happened? --->
The image creation process should be successful via Terraform as is the attributes supported by the REST API in version 3.
This should be supported as it is indicated in the documentation for the 'nutanix_image' resource:
* _data_source_reference - (Optional) Reference to a data source._(https://registry.terraform.io/providers/nutanix/nutanix/latest/docs/resources/image#data_source_reference)

```hcl
curl -X 'POST' \
  'https://prismCentral:9440/api/nutanix/v3/images' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'X-Nutanix-Client-Type: ui' \
  -d '{
        "spec":{
          "name":"linux-img--SCSI.0-1",
          "resources":{
            "image_type":"DISK_IMAGE",
            "data_source_reference":{
              "kind":"vm_disk",
              "uuid":"b62dbfa7-f19b-440a-938c-e28ea3c98d21"
            },
            "initial_placement_ref_list":[
              {
                "kind":"cluster",
                "uuid":"000608ae-3fc3-9376-62f5-0894efbcc894"
              }
            ]
          }
        },
        "metadata":{
          "kind":"image"
        },
        "api_version":"3.1.0"
      }'
}

Actual Behavior

│ Error: Unsupported argument │ │ on main.tf line 23, in resource "nutanix_image" "test": │ 23: data_source_reference = { │ │ An argument named "data_source_reference" is not expected here. ╵ ╷ │ Error: Unsupported argument │ │ on main.tf line 30, in resource "nutanix_image" "test": │ 30: initial_placement_ref_list = [ │ │ An argument named "initial_placement_ref_list" is not expected here.

However, it's worth noting that the 'initial_placement_ref_list' attribute is not mentioned in the documentation even though it is equally important when importing a 'VM_DISK' source image into the location of its placement method.

Steps to Reproduce

  1. terraform apply

    Important Factors

    This issue has already been addressed in '_Provider needs to support data_source_reference attribute for nutaniximage resource' (https://github.com/nutanix/terraform-provider-nutanix/issues/52) and is supposed to be fixed in 'Add missing API fields for structs' (https://github.com/nutanix/terraform-provider-nutanix/pull/80)."