2020-07-28 21:45:32 +00:00
|
|
|
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r
|
|
|
|
|
|
|
|
terraform {
|
|
|
|
required_version = ">= 0.12"
|
|
|
|
|
|
|
|
required_providers {
|
2021-01-12 22:21:07 +00:00
|
|
|
null = {
|
|
|
|
source = "hashicorp/null"
|
|
|
|
version = "~> 2.1"
|
|
|
|
}
|
|
|
|
template = {
|
|
|
|
source = "hashicorp/template"
|
|
|
|
version = "~> 2.1"
|
|
|
|
}
|
|
|
|
libvirt = {
|
2021-01-23 20:45:22 +00:00
|
|
|
source = "dmacvicar/libvirt"
|
2021-01-12 22:21:07 +00:00
|
|
|
version = ">= 0.6.3"
|
|
|
|
}
|
2020-07-28 21:45:32 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 22:34:05 +00:00
|
|
|
backend "etcdv3" {
|
|
|
|
endpoints = ["https://100.64.0.19:2379"]
|
|
|
|
lock = true
|
2020-08-10 23:43:24 +00:00
|
|
|
prefix = "/terraform-state/stack/"
|
2020-08-05 22:34:05 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2020-07-28 21:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provider "libvirt" {
|
2020-08-05 22:34:05 +00:00
|
|
|
uri = "qemu+tcp://dx30.localdomain/system"
|
2020-07-28 21:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "null_resource" "delay_10s" {
|
|
|
|
provisioner "local-exec" {
|
2021-01-23 20:45:22 +00:00
|
|
|
command = "sleep 120"
|
2020-07-28 21:45:32 +00:00
|
|
|
}
|
|
|
|
triggers = {
|
2021-01-24 20:49:30 +00:00
|
|
|
# trigger after last domain created
|
2021-01-23 20:45:22 +00:00
|
|
|
"after" = libvirt_domain.domains[var.number_domain - 1].id
|
2020-07-28 21:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Output Server IP
|
|
|
|
output "ip" {
|
2021-01-23 20:45:22 +00:00
|
|
|
value = libvirt_domain.domains.*.network_interface
|
2020-07-28 21:45:32 +00:00
|
|
|
depends_on = [null_resource.delay_10s]
|
|
|
|
}
|
2021-01-24 20:49:30 +00:00
|
|
|
|
|
|
|
resource "local_file" "write_address" {
|
|
|
|
|
|
|
|
content = <<-EOT
|
|
|
|
[all]
|
2021-01-24 23:12:17 +00:00
|
|
|
%{ for idx, s in libvirt_domain.domains.*.network_interface.0 ~}
|
|
|
|
${s.hostname} ansible_host=${s.addresses.0} index=${idx}
|
2021-01-24 20:49:30 +00:00
|
|
|
%{ endfor ~}
|
|
|
|
[all:vars]
|
|
|
|
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
|
|
|
|
EOT
|
|
|
|
|
|
|
|
filename = "../applications/stack_address.toml"
|
|
|
|
}
|