| layout | page_title | sidebar_current | description |
|---|---|---|---|
opennebula |
OpenNebula: opennebula_virtual_machine |
docs-opennebula-resource-virtual-machine |
Provides an OpenNebula virtual machine resource. |
Provides an OpenNebula virtual machine resource.
This resource allows you to manage virtual machines on your OpenNebula clusters. When applied, a new virtual machine is created. When destroyed, this virtual machine is removed.
resource "opennebula_virtual_machine" "example" {
count = 2
name = "virtual-machine-${count.index}"
description = "VM"
cpu = 1
vcpu = 1
memory = 1024
group = "terraform"
permissions = "660"
context = {
NETWORK = "YES"
HOSTNAME = "$NAME"
START_SCRIPT = "yum upgrade"
}
graphics {
type = "VNC"
listen = "0.0.0.0"
keymap = "fr"
}
os {
arch = "x86_64"
boot = "disk0"
}
disk {
image_id = opennebula_image.example.id
size = 10000
target = "vda"
driver = "qcow2"
}
on_disk_change = "RECREATE"
nic {
model = "virtio"
network_id = var.vnetid
security_groups = [opennebula_security_group.example.id]
# NOTE: To make this work properly ensure /etc/one/oned.conf contains: INHERIT_VNET_ATTR="DNS"
dns = "1.1.1.1"
}
vmgroup {
vmgroup_id = 42
role = "vmgroup-role"
}
sched_requirements = "FREE_CPU > 60"
tags = {
environment = "example"
}
template_section {
name = "example"
elements = {
key1 = "value1"
}
}
}The following arguments are supported:
name- (Required) The name of the virtual machine.description: (Optional) The description of the template.permissions- (Optional) Permissions applied on virtual machine. Defaults to the UMASK in OpenNebula (in UNIX Format: owner-group-other => Use-Manage-Admin).template_id- (Optional) If set, VM are instantiated from the template ID. See Instantiate from a template for details. Changing this argument triggers a new resource.pending- (Optional) Pending state during VM creation. Defaults tofalse.cpu- (Optional) Amount of CPU shares assigned to the VM. Mandatory iftemplate_idis not set.vpcu- (Optional) Number of CPU cores presented to the VM.memory- (Optional) Amount of RAM assigned to the VM in MB. Mandatory iftemplate_idis not set.context- (Optional) Array of free form key=value pairs, rendered and added to the CONTEXT variables for the VM. Recommended to include:NETWORK = "YES"andSET_HOSTNAME = "$NAME". If atemplate_idis set, see Instantiate from a template for details.graphics- (Optional) See Graphics parameters below for details.os- (Optional) See OS parameters below for details.disk- (Optional) Can be specified multiple times to attach several disks. See Disk parameters below for details.nic- (Optional) Can be specified multiple times to attach several NICs. See Nic parameters below for details.keep_nic_order- (Optional) Indicates if the provider should keep NIC list ordering at update.vmgroup- (Optional) See VM group parameters below for details. Changing this argument triggers a new resource.group- (Optional) Name of the group which owns the virtual machine. Defaults to the caller primary group.raw- (Optional) Allow to pass hypervisor level tuning content. See Raw parameters below for details.sched_requirements- (Optional) Scheduling requirements to deploy the resource following specific rule.sched_ds_requirements- (Optional) Storage placement requirements to deploy the resource following specific rule.tags- (Optional) Map of tags (key=value) assigned to the resource. Override matching tags present in thedefault_tagsatribute when configured in theproviderblock. See tags usage related documentation for more information.timeout- (Deprecated) Timeout (in Minutes) for VM availability. Defaults to 3 minutes.lock- (Optional) Lock the VM with a specific lock level. Supported values:USE,MANAGE,ADMIN,ALLorUNLOCK.on_disk_change- (Optional) Select the behavior for changing disk images. Supported values:RECREATEorSWAP(default).RECREATEforces recreation of the vm andSWAPadopts the standard behavior of hot-swapping the disks. NOTE: This property does not affect the behavior of adding new disks.hard_shutdown- (Optional) If the VM doesn't have ACPI support, it immediately poweroff/terminate/reboot/undeploy the VM. Defaults to false.template_section- (Optional) Allow to add a custom vector. See Template section parameters
graphics supports the following arguments:
type- (Required) Generally set to VNC.listen- (Required) Binding address.port- (Optional) Binding Port.keymap- (Optional) Keyboard mapping.passwd- (Optional) VNC's password, conflicts with random_passwd.random_passwd- (Optional) Randomized VNC's password, conflicts with passwd.
os supports the following arguments:
arch- (Required) Hardware architecture of the Virtual machine. Must fit the host architecture.boot- (Optional)OSdisk to use to boot on.machine- (Optional) libvirt machine type.kernel- (Optional) Path to theOSkernel to boot the image in the host.kernel_ds- (Optional) Image to be used as kernel. (see !!)initrd- (Optional) Path to the initrd image in the host.initrd_ds- (Optional) Image to be used as ramdisk. (see !!)root- (Optional) Device to be mounted as root.kernel_cmd- (Optional) Arguments for the booting kernel.bootloader- (Optional) Path to the bootloader executable.sd_disk_bus- (Optional) Bus for disks with sd prefix, eitherscsiorsata, if attribute is missing, libvirt chooses itself.uuid- (Optional) Unique ID of the VM.firmware- (Optional) Firmware type or firmware path. Possible values:BIOSor path for KVM,BIOSorUEFIfor vCenter.firmware_secure- (Optional) Enable Secure Boot. (Can betrueorfalse).- (!!) Use one of
kernel_dsorkernel(andinitrdorinitrd_ds).
disk supports the following arguments
image_id- (Optional) ID of the image to attach to the virtual machine. Defaults to -1 if not set: this skip Image attchment to the VM. Conflicts withvolatile_typeandvolatile_format.size- (Optional) Size (in MB) of the image. If set, it will resize the image disk to the targeted size. The size must be greater than the current one.target- (Optional) Target name device on the virtual machine. Depends of the imagedev_prefix.driver- (Optional) OpenNebula image driver.volatile_type- (Optional) Type of the disk:swaporfs. Typeswapis not supported in vcenter. Conflicts withimage_id.volatile_format- (Optional) Format of the Image:raworqcow2. Conflicts withimage_id.
Minimum 1 item. Maximum 8 items.
A disk update will be triggered in adding or removing a disk section, or by a modification of any of these parameters: image_id, target, driver
nic supports the following arguments
network_id- (Optional) ID of the virtual network to attach to the virtual machine.ip- (Optional) IP of the virtual machine on this network.mac- (Optional) MAC of the virtual machine on this network.model- (Optional) Nic model driver. Example:virtio.virtio_queues- (Optional) Virtio multi-queue size. Only ifmodelisvirtio.physical_device- (Optional) Physical device hosting the virtual network.security_groups- (Optional) List of security group IDs to use on the virtual network.method- (Optional) Method of obtaining IP addresses (empty orstatic,dhcp,skip).gateway- (Optional) Default gateway set for the NIC.dns- (Optional) DNS server set for the NIC. Please make sureINHERIT_VNET_ATTR="DNS"is added to/etc/one/oned.conf.network_mode_auto- (Optional) A boolean letting the scheduler pick the Virtual Networks the VM NICs will be attached to. Can only be used at VM creation.sched_requirements- (Optional) A boolean expression to select virtual networks (evaluates to true) to attach the NIC, whennetwork_mode_autois true. Can only be used at VM creation.sched_rank- (Optional) Arithmetic expression to sort the suitable Virtual Networks for this NIC, whennetwork_mode_autois true. Can only be used at VM creation.
Minimum 1 item. Maximum 8 items.
A NIC update will be triggered in adding or removing a nic section, or by a modification of any of these parameters: network_id, ip, mac, security_groups, physical_device
vmgroup supports the following arguments:
vmgroup_id- (Required) ID of the VM group to use.role- (Required) role of the VM group to use.
raw supports the following arguments:
type- (Required) - Hypervisor. Supported values:kvm,lxd,vmware.data- (Required) - Raw data to pass to the hypervisor.
template_section supports the following arguments:
name- (Optional) The vector name.elements- (Optional) Collection of custom tags.
The following attribute are exported:
id- ID of the virtual machine.uid- User ID whom owns the virtual machine.gid- Group ID which owns the virtual machine.uname- User Name whom owns the virtual machine.gname- Group Name which owns the virtual machine.state- State of the virtual machine.lcmstate- LCM State of the virtual machine.template_disk- whentemplate_idis used and the template define some disks, this contains the template disks description.template_nic- whentemplate_idis used and the template define some NICs, this contains the template NICs description.tags_all- Result of the applieddefault_tagsand then resourcetags.default_tags- Default tags defined in the provider configuration.template_tags- Whentemplate_idwas set this keeps the template tags.template_section_names- Whentemplate_idwas set this keeps the template section names only.
network_id- ID of the image attached to the virtual machine.nic_id- nic attachment identifiernetwork- network namecomputed_ip- IP of the virtual machine on this network.computed_mac- MAC of the virtual machine on this network.computed_model- Nic model driver.computed_virtio_queues- Virtio multi-queue size.computed_physical_device- Physical device hosting the virtual network.computed_security_groups- List of security group IDs to use on the virtual.computed_method- Method of obtaining IP addresses (empty orstatic,dhcp,skip).computed_gateway- Default gateway set for the NIC.computed_dns- DNS server set for the NIC.
image_id- ID of the image attached to the virtual machine.disk_id- disk attachment identifiercomputed_size- Size (in MB) of the image attached to the virtual machine. Not possible to change a cloned image size.computed_target- Target name device on the virtual machine. Depends of the imagedev_prefix.computed_driver- OpenNebula image driver.
nic_id- nic attachment identifiernetwork- network namecomputed_ip- IP of the virtual machine on this network.computed_mac- MAC of the virtual machine on this network.computed_model- Nic model driver.computed_virtio_queues- Virtio multi-queue size.computed_physical_device- Physical device hosting the virtual network.computed_security_groups- List of security group IDs to use on the virtual.computed_method- Method of obtaining IP addresses (empty orstatic,dhcp,skip).computed_gateway- Default gateway set for the NIC.computed_dns- DNS server set for the NIC.
disk_id- disk attachment identifiercomputed_size- Size (in MB) of the image attached to the virtual machine. Not possible to change a cloned image size.computed_target- Target name device on the virtual machine. Depends of the imagedev_prefix.computed_driver- OpenNebula image driver.computed_volatile_format- Format of the Image:raworqcow2.
When the attribute template_id is set, here is the behavior:
For all parameters excepted context: parameters present in VM overrides parameters defined in template. For context: it merges them.
For disks and NICs defined in the template, if they are not overriden, are described in template_disk and template_nic attributes of the instantiated VM and are not modifiable anymore.
opennebula_virtual_machine can be imported using its ID:
terraform import opennebula_virtual_machine.example 123