Open chafey opened 6 years ago
To add the VDI to a VM you would do something like:
hard_drive {
vdi_uuid = "${xenserver_vdi.data.id}"
mode = "RW"
}
In the VM resource block where data
is the identifier given to the VDI you're creating.
To mount it within the VM you would have to do some provisioning after Terraform, for example with Ansible.
I added this, but the VDI is not attached to the VM, here is what my tf file looks like (note that the template has the OS hard drive attached to it):
resource "xenserver_vdi" "xxx-data-vdi" {
sr_uuid = "4758064c-924a-c671-9c26-8321b6c207c8"
name_label = "xxx-data-vdi"
size = 20073741824 # 20GB
}
resource "xenserver_vm" "xxx-vm" {
base_template_name = "Ubuntu 16.04 Template"
name_label = "xxx-ubuntu-vdi"
static_mem_min = 8589934592
static_mem_max = 8589934592
dynamic_mem_min = 8589934592
dynamic_mem_max = 8589934592
vcpus = 1
boot_order = "c"
hard_drive {
is_from_template = true
user_device = "0"
} # Template VM HDD
hard_drive {
is_from_template = false
user_device = "4"
vdi_uuid = "${xenserver_vdi.xxx-data-vdi.id}"
mode = "RW"
}
cdrom {
is_from_template = true
user_device = "3"
}
}
Further investigation is indicating that no VBD is being created, hence the VDI is not attached to the VM. Any help would be appreciated
Bug seems to be here:
https://github.com/ringods/terraform-provider-xenserver/blob/master/xenserver/resource_vbd.go#L371
This condition is always passing for my VDI. I was able to workaround this by changing it to:
if ud, ok := data[vbdSchemaUserDevice]; ok && ud != "" {
log.Println("Skipping VBDm user_device=%s", ud)
continue
}
And not setting user_device. No idea if this is the right fix, but thought I would post it here
Removing user_device
and changing that check is exactly what I did.
I actually already opened a pull request to fix it: #33. Forgot about it when replying previously though.
Nice - hopefully we can that merged soon. Do you have any documentation about the purpose of user_device? I am new to xen/terraform so not sure what this is suppose to do. Thanks
My understanding is that it's just a number (0 to 7) identifying the virtual device on a VM. In this Terraform provider it's only used to specify existing devices from a template. So when you have multiple devices in a template you can select them by the userdevice number.
See also http://xapi-project.github.io/xen-api/classes/vbd.html.
OK - I am not clear what it actually does though? Is the user_device a number I assign to items or does it need to match the way the VM is actually configured? Its purpose and use it still unclear to me - if there is no reason for it, perhaps we should get rid of it?
I am new to terraform and xen server so forgive me if this is a noob question. I would like to use terraform and xen server to create a new VM with two separate disks - one for the OS/Application and one for the application data. My VM template already has the OS disk connected to it so I think I have that covered. I am also able to create a VDI using xenserver_vdi, but I don't know how to attach that VDI to the VM and mount it say /data. Any ideas how to do this?