Skip to content

Terraform module for creating libvirt domains (VMs) with cloud-init and optional Ansible Automation Platform integration.

License

Notifications You must be signed in to change notification settings

makeitworkcloud/terraform-libvirt-domain

Repository files navigation

terraform-libvirt-domain

Terraform module for creating libvirt domains (VMs) with cloud-init and optional Ansible Automation Platform integration.

Usage

module "vm" {
  source = "git::https://github.com/makeitworkcloud/terraform-libvirt-domain.git?ref=v1.0.0"

  name        = "my-vm"
  description = "My virtual machine"
  vcpu        = 2
  memory      = 4096

  cloudinit_meta_data_template      = file("${path.module}/templates/meta-data.tpl")
  cloudinit_meta_data_vars          = { hostname = "my-vm" }
  cloudinit_user_data_template      = file("${path.module}/templates/user-data.tpl")
  cloudinit_user_data_vars          = {}
  cloudinit_network_config_template = file("${path.module}/templates/network-config.tpl")
  cloudinit_network_config_vars     = { ip_address = "192.168.1.100" }

  private_ip_addr = "192.168.1.100"
  proxyhost       = "bastion.example.com"
}

Requirements

Name Version
terraform >= 1.3
aap ~> 1.4.0
libvirt ~> 0.9.0

Providers

Name Version
aap ~> 1.4.0
libvirt ~> 0.9.0

Modules

No modules.

Resources

Name Type
aap_host.host resource
aap_job.job resource
libvirt_cloudinit_disk.commoninit resource
libvirt_domain.vm resource
libvirt_volume.boot resource
libvirt_volume.cloudinit resource
libvirt_volume.extra resource
aap_inventory.inventory data source
aap_job_template.job_template data source
aap_organization.org data source

Inputs

Name Description Type Default Required
aap_inventory_name Name of the AAP inventory to use. string "libvirt-infra" no
aap_job_template_name Name of the AAP job template to run. If left empty, will default to configure_ string "" no
aap_org_name Name of the Ansible Automation Platform (AAP) organization. string "Default" no
boot_image_url URL for the base QCOW2 image used as the boot disk. string "https://download.fedoraproject.org/pub/fedora/linux/releases/43/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-43-1.6.x86_64.qcow2" no
bridge_name Name of the network bridge for the second network interface. string "nm-bridge" no
cloudinit_meta_data_template The template content for cloud-init meta-data configuration. string n/a yes
cloudinit_meta_data_vars Variable map for the cloud-init meta-data template. map(string) n/a yes
cloudinit_network_config_template The template content for cloud-init network configuration. string n/a yes
cloudinit_network_config_vars Variable map for the cloud-init network configuration template. map(string) n/a yes
cloudinit_user_data_template The template content for cloud-init user-data configuration. string n/a yes
cloudinit_user_data_vars Variable map for the cloud-init user-data template. Set to {} if not used. map(string) n/a yes
description Description for the libvirt domain (virtual machine). string "" no
enable_aap Whether to provision Ansible Automation Platform (AAP) resources for this domain. bool false no
extra_volumes List of additional volumes to attach to the domain. Each object should contain:
- name: Name of the volume.
- size: Size of the volume in bytes.
Example:
[
{
name = "runner-var-lib-docker.qcow2"
size = 107374182400
}
]
list(object({
name = string
size = number
}))
[] no
memory Amount of memory (in MB) to assign to the domain. number 2048 no
name The name of the libvirt domain (virtual machine) and related resources. string n/a yes
private_ip_addr Private IP address to assign to the VM (used for network config and inventory). string n/a yes
proxyhost Proxy host for SSH connection, used in ansible_ssh_common_args. string n/a yes
storage_pool Name of the libvirt storage pool where volumes will be created. string "default" no
vcpu Number of virtual CPUs to assign to the domain. number 1 no

Outputs

Name Description
boot_volume_id The ID of the boot volume
cloudinit_disk_id The ID of the cloud-init disk
domain_id The ID of the libvirt domain
domain_name The name of the libvirt domain

About

Terraform module for creating libvirt domains (VMs) with cloud-init and optional Ansible Automation Platform integration.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published