Closed eltphat closed 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"
virtual_disks = [ { virtual_disk_id = "${esxi_virtual_disk.cache_disk.id}" slot = "0:1" }, ] }
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
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"
}
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.
Sorry, that feature (updating a VM to add a disk) is not implemented, so terraform needs to re-create the resource.
Many Thanks josenk.
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.
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
I created 1 vm and 1 vdisk at first. After that i add that vdisk to vm but it destroy and create new all.