This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
kubic-kvm.tf
91 lines (72 loc) · 1.82 KB
/
kubic-kvm.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
terraform {
required_version = ">= 0.13"
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = "0.6.3"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}
resource "libvirt_volume" "kubic_image" {
name = "kubic_image"
source = "./kubic.qcow2"
}
resource "libvirt_volume" "os_volume" {
name = "os_volume-${count.index}"
base_volume_id = libvirt_volume.kubic_image.id
count = var.count_vms
}
resource "libvirt_volume" "data_volume" {
name = "data_volume-${count.index}"
// 6 * 1024 * 1024 * 1024
size = 6442450944
count = var.count_vms
}
resource "libvirt_network" "kubic_network" {
name = "kubic-network"
mode = var.network_mode
domain = var.dns_domain
dns {
enabled = true
}
addresses = [var.network_cidr]
}
data "template_file" "ignition_data" {
count = var.count_vms
template = file("commoninit.ign")
vars = {
hostname = "kubic-${count.index}"
}
}
resource "libvirt_ignition" "kubic_ignition" {
name = "kubic-ignition-${count.index}"
content = element(data.template_file.ignition_data.*.rendered, count.index)
count = var.count_vms
}
resource "libvirt_domain" "kubic_domain" {
name = "kubic-kubeadm-${count.index}"
cpu = {
mode = "host-passthrough"
}
memory = var.memory
vcpu = var.vcpu
disk {
volume_id = element(libvirt_volume.os_volume.*.id, count.index)
}
disk {
volume_id = element(libvirt_volume.data_volume.*.id, count.index)
}
network_interface {
network_name = "kubic-network"
hostname = "kubic-kubeadm-${count.index}"
wait_for_lease = true
}
coreos_ignition = element(libvirt_ignition.kubic_ignition.*.id, count.index)
count = var.count_vms
}
output "ips" {
value = libvirt_domain.kubic_domain.*.network_interface.0.addresses
}