Skip to content

Virtual Machines

Corey Melanson edited this page Jul 19, 2018 · 1 revision

Resource Parameters

The opennebula_vm resource accepts the following parameters:

Parameter Optional Description
name Required Name of the new virtual machine
permissions Optional Chmod the image, defaults to the UMASK in OpenNebula
template_id Optional Create the VM from this OpenNebula template ID. Conflicts with all parameters lower in this list.
cpu Optional Amount of CPU shares assigned to the VM
vcpu Optional Number of CPU cores presented to the VM
memory Optional Amount of RAM assigned to the VM in MB
context Optional Array of free form key=value pairs, rendered and added to the CONTEXT variables for the VM, recommended to include at a minimum: NETWORK = "YES" and HOSTNAME = "$NAME"
graphics Optional See Graphics parameter table below
os Optional See OS parameter table below
disk Required Can be specified multiple times to attach several disks, see Disk parameter table below
nic Required Can be specified multiple times to attach several NICs, see NIC parameter table below
raw Optional See RAW parameter table below

Please note! While some parameters are optional (eg raw), if you add this you are required to define the required parameters from the table below. If you don't define it, the OpenNebula defaults will be used which are generally acceptable.

Graphics parameters:

Parameter Optional Description
type Optional Generally set to VNC
listen Optional Should be set to 0.0.0.0 if defined

OS parameters:

Parameter Optional Description
arch Required Should be set to x86_64 if defined
boot Required Should generally be set to disk0 to boot from the OS disk

Disk parameters:

Parameter Optional Description
image_id Required ID number of the image to attach to the VM
size Optional Resize the disk to this amount (in MB)
target Optional Generally set to "vda" for the OS disk
driver Optional Generally set to qcow2 for OS disks on NFS and raw for persistent datablock images

NIC parameters:

Parameter Optional Description
model Required Generally should be set to "virtio" if defined
network_id Required VNET ID to attach the NIC to
ip Optional Make OpenNebula assign this IP to the VM if it's available in the VNET. VM will fail to create if this IP is unavailable.
security_groups Optional List of Security Group ID numbers to apply on top of the ones in the VNET

RAW parameters:

Parameter Optional Description
data Required Raw XML data to pass to libvirt
type Required Set this to "kvm" if raw data is required

Examples

Create a basic VM attached to a security group and image:

data "template_file" "cloudinit" {
  template = "${file("cloud-init.yaml")}"
}

resource "opennebula_vm" "demo" {
  name = "tfdemovm"
  cpu = 1
  vcpu = 1
  memory = 1024
  
  context {
    NETWORK = "YES"
    HOSTNAME = "$NAME"
    USER_DATA = "${data.template_file.cloudinit.rendered}"
  }
  
  graphics {
    type = "VNC"
    listen = "0.0.0.0"
  }
  
  os {
    arch = "x86_64"
    boot = "disk0"
  }
  
  disk {
    image_id = "${opennebula_image.osimage.id}"
    size = 10000
    target = "vda"
    driver = "qcow2"
  }
  
  nic {
    model = "virtio"
    network_id = "${var.vnetid}"
    security_groups = ["${opennebula_secgroup.mysecgroup.id}"]
  }
}
 
output "vm_ips" {
  value = "${join(",",opennebula_vm.demo.*.ip)}"
}