Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider prevents disk resizing at VM creation time #130

Closed
waddles opened this issue May 25, 2020 · 1 comment · Fixed by #137
Closed

Provider prevents disk resizing at VM creation time #130

waddles opened this issue May 25, 2020 · 1 comment · Fixed by #137

Comments

@waddles
Copy link

waddles commented May 25, 2020

Nutanix Cluster Information

  • AOS Version 5.10.9.1 LTS
  • Prism Central Version 5.11.2.1

Terraform Version

Terraform v0.12.23
+ provider.nutanix v1.0.2

Affected Resource(s)

  • nutanix_virtual_machine

Terraform Configuration Files

variable "endpoint" {
  type = string
}
variable "cluster" {
  type = string
}
variable "user" {
  type = string
}
variable "password" {
  type = string
}
variable "name" {
  type = string
}
variable "image" {
  type = string
  default = "TPL - Ubuntu 16.04.1 mini"
}
variable "disks" {
  type = list(object({
    label = string
    sizeMb = number
  }))
  default = [{"label":"os","sizeMb":10240},{"label":"data","sizeMb":5120}]
}

data "nutanix_clusters" "clusters" {}
data "nutanix_image" "os_disk" {
  image_name = var.image
}

locals {
  cluster_uuid = [
    for cluster in data.nutanix_clusters.clusters.entities:
      cluster.metadata.uuid if cluster.name == upper(split(".", var.cluster)[0])
    ][0]
}

resource "nutanix_virtual_machine" "my_vm" {
  name = var.name
  cluster_uuid = local.cluster_uuid

  disk_list {
    data_source_reference = {
      kind = "image"
      uuid = data.nutanix_image.os_disk.id
    }

    device_properties {
      disk_address = {
        device_index = 0
        adapter_type = "SCSI"
      }
      device_type = "DISK"
    }
    disk_size_mib = [for disk in var.disks: disk["sizeMb"] if disk["label"] == "os"][0]
  }
}

Expected Behavior

VM should be created with disk image cloned as first disk and size increased to match spec.

Actual Behavior

Error: "disk_list.0.disk_size_mib": conflicts with disk_list.0.data_source_reference

Steps to Reproduce

  1. terraform apply

Important Factors

Nutanix API v3 allows disk resizing at VM creation time. The following spec has been confirmed to work correctly when POSTed to /api/nutanix/v3/vms:

{
  "metadata": {
    "kind": "vm"
  },
  "spec": {
    "name": "atestvm",
    "resources": {
      "disk_list": [
        {
          "device_properties": {
            "disk_address": {
              "device_index": 0,
              "adapter_type": "SCSI"
            },
            "device_type": "DISK"
          },
          "data_source_reference": {
            "kind": "image",
            "uuid": "1293e13d-554a-4fd5-b2a8-2cf16f9c5c40"
          },
          "disk_size_mib": 20480
        }
      ]
    },
    "cluster_reference": {
      "kind": "cluster",
      "uuid": "00052f47-4686-eeb8-0000-00000000b0ae"
    }
  }
}

​The 5GB disk image is increased to 20GB when cloned.

References

@waddles
Copy link
Author

waddles commented May 26, 2020

I had a look at the code and simply commenting https://github.com/terraform-providers/terraform-provider-nutanix/blob/4406e9e4a476604a9b8d6693cd3162eab0b0ea89/nutanix/resource_nutanix_virtual_machine.go#L1716 so hasDSRef is always false seems to work correctly in every test I have tried. I think that is an unnecessary check causing a false negative error.

PacoDw pushed a commit that referenced this issue Jun 24, 2020
PacoDw added a commit that referenced this issue Jun 24, 2020
yannickstruyf3 added a commit to yannickstruyf3/terraform-provider-nutanix that referenced this issue Nov 9, 2021
yannickstruyf3 pushed a commit to yannickstruyf3/terraform-provider-nutanix that referenced this issue Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant