# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r terraform { required_version = ">= 0.12" required_providers { null = { source = "hashicorp/null" version = "~> 2.1" } template = { source = "hashicorp/template" version = "~> 2.1" } libvirt = { source = "dmacvicar/libvirt" version = ">= 0.6.3" } } backend "etcdv3" { endpoints = ["https://100.64.0.19:2379"] lock = true prefix = "/terraform-state/stack/" cacert_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/ca.pem" cert_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/kubernetes.pem" key_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/kubernetes-key.pem" } } provider "libvirt" { uri = "qemu+tcp://dx30.localdomain/system" } resource "null_resource" "delay_controllers_10s" { count = var.number_controller > 0 ? 1 : 0 provisioner "local-exec" { command = "sleep 60" } triggers = { # trigger after last domain controller and laster domain worker created "after" = libvirt_domain.controllers[var.number_controller - 1].id } } resource "null_resource" "delay_workers_10s" { count = var.number_worker > 0 ? 1 : 0 provisioner "local-exec" { command = "sleep 60" } triggers = { # trigger after last domain controller and laster domain worker created "after" = libvirt_domain.workers[var.number_worker - 1].id } } # Output Server IP output "ip" { value = concat(libvirt_domain.controllers.*.network_interface, libvirt_domain.workers.*.network_interface) depends_on = [null_resource.delay_controllers_10s, null_resource.delay_workers_10s] } resource "local_file" "write_address" { content = <<-EOT # controller domain [controller] %{ for idx, s in libvirt_domain.controllers.*.network_interface.0 ~} %{ if length(s.addresses) > 0 ~} ${s.hostname} ansible_host=${s.addresses.0} index=${idx} %{ endif ~} %{ endfor ~} # worker domain [worker] %{ for idx, s in libvirt_domain.workers.*.network_interface.0 ~} %{ if length(s.addresses) > 0 ~} ${s.hostname} ansible_host=${s.addresses.0} index=${idx} %{ endif ~} %{ endfor ~} [all:children] controller worker [all:vars] ansible_ssh_extra_args='-o StrictHostKeyChecking=no' EOT filename = "../applications/stack_address.toml" }