Skip to content

Attaching disks to OVA deploy #1138

@kvandenhoute-eurocontrol

Description

Nutanix Cluster Information

Version pc.7.5.0.1
NCC Version: ncc-5.3.0

Terraform Version

registry.terraform.io/nutanix/nutanix v2.4.2

Affected Resource(s)

nutanix_ova_vm_deploy_v2

Terraform Configuration Files

resource "nutanix_ova_vm_deploy_v2" "vm" {
  ext_id   = local.ova.ext_id

  override_vm_config {
...
    dynamic "disks" {
      for_each = { for idx, disk in var.disks : idx => disk if disk.type == "ATTACHED" }
      content {
        disk_address {
          bus_type = "SCSI"
          index    = disks.key
        }
        backing_info {
          vm_disk {
            disk_size_bytes = disks.value.size_gb * 1024 * 1024 * 1024
            storage_container {
              ext_id = <id>
            }
          }
        }
      }
    }
...
}

Debug Output

The plan works:

  + resource "nutanix_ova_vm_deploy_v2" "vm" {
      + override_vm_config {
...
          + disks {
              + ext_id = (known after apply)

              + backing_info {
                  + vm_disk {
                      + disk_ext_id              = (known after apply)
                      + disk_size_bytes          = 1073741824000
                      + is_migration_in_progress = (known after apply)

                      + storage_container {
                          + ext_id = "bdee82a5-8340-40c5-99b3-19cfc180f84d"
                        }
                    }
                }

              + disk_address {
                  + bus_type = "SCSI"
                  + index    = 0
                }
            }
...
        }

but when applying it crashes, since the deployed OVA already has one (or more disks) attached (included in the ova):

│ Error: error waiting for disk creation (ZXJnb24=:3b4fe56f-9a0d-5f4b-9268-c7b9f0a87df7): error_detail: Failed to perform the operation on VM with UUID 'd611ff75-bcf4-45a4-4bcf-3d20579b896d' as the disk bus with type 'scsi' and index '0' is already in use., progress_message: 100
│ 
│   with module.dedicated_vms_0.module.nexus.nutanix_ova_vm_deploy_v2.vm,
│   on ../../modules/ahv-virtual-machine-v2/base_ova_virtual_machine/virtualmachine.tf line 1, in resource "nutanix_ova_vm_deploy_v2" "vm":
│    1: resource "nutanix_ova_vm_deploy_v2" "vm" {

If you change the disk_address to an empty spot:

...
    dynamic "disks" {
      for_each = { for idx, disk in var.disks : idx => disk if disk.type == "ATTACHED" }
      content {
        disk_address {
          bus_type = "SCSI"
          index    = disks.key + var.amount_of_disks_in_ova # in my case + 1
        }
...

you can succesfully apply and everything is succesful:

Image

However, after applying the state is incorrect, because when applying again - without any changes to the terraform -, it wants to remove the disk:

          ~ disks {
                # (1 unchanged attribute hidden)

              ~ backing_info {
                  ~ vm_disk {
                      ~ disk_size_bytes          = 64424509440 -> 1073741824000
                        # (2 unchanged attributes hidden)

                      ~ storage_container {
                          ~ ext_id = "cbfaf36c-2f7b-4330-b695-26b7a6395f2d" -> "bdee82a5-8340-40c5-99b3-19cfc180f84d"
                        }
                    }
                }

              ~ disk_address {
                  ~ index    = 0 -> 1
                    # (1 unchanged attribute hidden)
                }
            }
          - disks {
              - ext_id = "46f7e56d-435f-4542-8ac7-33f0d9c25f7c" -> null

              - backing_info {
                  - vm_disk {
                      - disk_ext_id              = "46f7e56d-435f-4542-8ac7-33f0d9c25f7c" -> null
                      - disk_size_bytes          = 1073741824000 -> null
                      - is_migration_in_progress = false -> null

                      - storage_container {
                          - ext_id = "bdee82a5-8340-40c5-99b3-19cfc180f84d" -> null
                        }
                    }
                }

              - disk_address {
                  - bus_type = "SCSI" -> null
                  - index    = 1 -> null
                }
            }

applying indeed removes the disk:

Image

and then the terraform crashes:

╷
│ Error: error waiting for disk (ZXJnb24=:b0d72552-781b-5fce-8533-7ae000ff49b4) to be updated: error_detail: Failed to perform the operation on the VM with UUID '97c9d3fd-6194-476d-404d-bc867f973ea9', due to an invalid argument with key 'Disk Index' and value '1'., progress_message: 100
│ 
│   with module.dedicated_vms_0.module.nexus.nutanix_ova_vm_deploy_v2.vm,
│   on ../../modules/ahv-virtual-machine-v2/base_ova_virtual_machine/virtualmachine.tf line 1, in resource "nutanix_ova_vm_deploy_v2" "vm":
│    1: resource "nutanix_ova_vm_deploy_v2" "vm" {
│ 
╵

on a third apply no changes are required but the disk is gone.

Expected Behavior

I can specify disk index 0, and it appends to the already existing disks,
or
I use disk index (amount_of_disks_in_ova) + 1

In any case I expect the disk to stay on there after a second apply

Actual Behavior

It removes my extra disk on a second apply

Steps to Reproduce

Try to attach a disk to a nutanix_ova_vm_deploy_v2, after it applied, re-apply

References

I previously created and implemented #985, where this problem did not happen. Is my terraform input incorrect, or is this a later introduced bug in the provider?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions