josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
544 stars 154 forks source link

Can't add existing additional disk #20

Closed eltphat closed 5 years ago

eltphat commented 5 years ago

I created 1 vm and 1 vdisk at first. After that i add that vdisk to vm but it destroy and create new all.

eltphat commented 5 years ago

resource "esxi_virtual_disk" "cache_disk" { virtual_disk_disk_store = "${var.virtual_disk_disk_store}" virtual_disk_dir = "${var.virtual_disk_dir}" virtual_disk_name = "cache1.vmdk" virtual_disk_size = "${var.virtual_disk_size}" virtual_disk_type = "${var.virtual_disk_type}" } resource "esxi_guest" "proxy" { count = "1" guest_name = "proxy-${count.index + 1}" disk_store = "${var.disk_store}" boot_disk_type = "${var.boot_disk_type}" boot_disk_size = "${var.boot_disk_size}" memsize = "${var.memsize}" numvcpus = "${var.numvcpus}" power = "${var.power}"

clone_from_vm = "centos-7-20181204"

ovf_source = "/Volumes/DATA/OVF/centos-7-20181204.ovf"

virtual_disks = [ { virtual_disk_id = "${esxi_virtual_disk.cache_disk.id}" slot = "0:1" }, ] }

josenk commented 5 years ago

You cannot just "add the vdisk to the VM"... Terraform doesn't know about your manual work and it won't be in the state file tfstate file. Terraform will destroy what is wrong to make it right.

You need to import resources.

https://github.com/josenk/terraform-provider-esxi/wiki/How-to-import https://www.terraform.io/docs/import/index.html

eltphat commented 5 years ago

Maybe something went wrong here, I created 1 VM and 1 additional disk with terraform like this:

resource "esxi_virtual_disk" "cache_disk" { virtual_disk_disk_store = "${var.virtual_disk_disk_store}" virtual_disk_dir = "${var.virtual_disk_dir}" virtual_disk_name = "cache1.vmdk" virtual_disk_size = "${var.virtual_disk_size}" virtual_disk_type = "${var.virtual_disk_type}" } resource "esxi_guest" "proxy" { count = "1" guest_name = "proxy-${count.index + 1}" disk_store = "${var.disk_store}" boot_disk_type = "${var.boot_disk_type}" boot_disk_size = "${var.boot_disk_size}" memsize = "${var.memsize}" numvcpus = "${var.numvcpus}" power = "${var.power}"

clone_from_vm = "centos-7-20181204"

ovf_source = "/Volumes/DATA/OVF/centos-7-20181204.ovf"

}

After applying that config, I add that additional disk to vm but it can not work with this config

virtual_disks = [ { virtual_disk_id = "${esxi_virtual_disk.cache_disk.id}" slot = "0:1" }, ]

Notes: But It worked when I created a vm include that additional disk from the beginning.

josenk commented 5 years ago

Sorry, that feature (updating a VM to add a disk) is not implemented, so terraform needs to re-create the resource.

eltphat commented 5 years ago

Many Thanks josenk.

josenk commented 5 years ago

I'll be considering adding this feature in a future release... For now, you cannot update (add or remove) the esxi_virtual_disk resource from the esxi_guest resource.

josenk commented 5 years ago

BTW: I've added support to attach an existing disk to the VM...

https://github.com/josenk/terraform-provider-esxi/releases/tag/V1.3.0