data "netbox_prefix" "network" { cidr = var.netbox_prefix } resource "netbox_available_ip_address" "available_ip" { prefix_id = data.netbox_prefix.network.id description = var.name dns_name = var.dns_name } output "ip_addr" { value = netbox_available_ip_address.available_ip.ip_address } data "xenorchestra_sr" "local_storage" { name_label = var.storage } data "xenorchestra_network" "network" { name_label = var.network pool_id = data.xenorchestra_pool.pool.id } data "xenorchestra_pool" "pool" { name_label = var.pool } data "xenorchestra_template" "template" { name_label = var.template } resource "xenorchestra_vm" "vm_deployed" { memory_max = var.ram * 1024 * 1024 * 1024 cpus = var.cpu cloud_config = templatefile("cloud_config.tftpl", { hostname = var.name ssh_keys = var.ssh_keys }) cloud_network_config = templatefile("cloud_network_config.tftpl", { ip = "${replace(netbox_available_ip_address.available_ip.ip_address, "var.netmask_netbox", var.netmask)}" gateway = var.gateway }) name_label = var.name name_description = var.desc template = data.xenorchestra_template.template.id # Prefer to run the VM on the primary pool instance affinity_host = data.xenorchestra_pool.pool.master network { network_id = data.xenorchestra_network.network.id } disk { sr_id = data.xenorchestra_sr.local_storage.id name_label = var.name size = var.disk_size * 1024 * 1024 * 1024 } tags = var.vm_tags // Override the default create timeout from 5 mins to 20. timeouts { create = "20m" } } # Generate inventory file resource "local_file" "inventory" { filename = "inventory" content = <