first functional commit
This commit is contained in:
74
main.tf
Normal file
74
main.tf
Normal file
@@ -0,0 +1,74 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "libvirt" {
|
||||
uri = "qemu:///system"
|
||||
}
|
||||
|
||||
data "template_file" "user_data" {
|
||||
template = "${file("${path.module}/templates/cloud_init.cfg")}"
|
||||
vars = {
|
||||
init_ssh_auth_key = var.init_ssh_auth_key
|
||||
init_user_name = var.init_user_name
|
||||
}
|
||||
}
|
||||
|
||||
resource "libvirt_cloudinit_disk" "kybus_commoninit" {
|
||||
name = "kybus_commoninit.iso"
|
||||
pool = "default"
|
||||
user_data = "${data.template_file.user_data.rendered}"
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "kybus_kybus" {
|
||||
name = "kybus_kybus"
|
||||
pool = "default"
|
||||
source = var.kybus_source
|
||||
format = "qcow2"
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "kybus_kybus_resized" {
|
||||
name = "kybus_kybus_resized"
|
||||
base_volume_id = libvirt_volume.kybus_kybus.id
|
||||
pool = "default"
|
||||
size = var.base_disk_size
|
||||
}
|
||||
|
||||
resource "libvirt_domain" "kybus_kybus_vm" {
|
||||
name = "kybus_kybus"
|
||||
memory = var.base_ram_size
|
||||
vcpu = 2
|
||||
|
||||
network_interface {
|
||||
network_name = "default"
|
||||
wait_for_lease = true
|
||||
}
|
||||
|
||||
disk {
|
||||
volume_id = "${libvirt_volume.kybus_kybus_resized.id}"
|
||||
}
|
||||
|
||||
cloudinit = "${libvirt_cloudinit_disk.kybus_commoninit.id}"
|
||||
|
||||
console {
|
||||
type = "pty"
|
||||
target_type = "serial"
|
||||
target_port = "0"
|
||||
}
|
||||
|
||||
graphics {
|
||||
type = "spice"
|
||||
listen_type = "address"
|
||||
autoport = true
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = "sleep 10 && ANSIBLE_STDOUT_CALLBACK=yaml ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u '${var.init_user_name}' --private-key /root/.ssh/key -i '${self.network_interface[0].addresses[0]},' site.yml"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user