modularize tf infrastructure
This commit is contained in:
parent
493daeeb29
commit
6dae248c01
14 changed files with 291 additions and 151 deletions
62
tofu/service-vm/main.tf
Normal file
62
tofu/service-vm/main.tf
Normal file
|
@ -0,0 +1,62 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "0.7.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "rootfs" {
|
||||
name = "${var.domain_name}-rootfs.qcow2"
|
||||
pool = var.domain_pool
|
||||
base_volume_id = var.domain_base_volume_id
|
||||
}
|
||||
|
||||
resource "libvirt_volume" "data" {
|
||||
name = "${var.domain_name}-data.qcow2"
|
||||
pool = var.domain_pool
|
||||
size = var.domain_data_volume_size
|
||||
format = "qcow2"
|
||||
|
||||
lifecycle {
|
||||
prevent_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "libvirt_ignition" "ign" {
|
||||
name = "${var.domain_name}-service.ign"
|
||||
pool = var.domain_pool
|
||||
content = "${var.domain_ignition_path}"
|
||||
}
|
||||
|
||||
resource "libvirt_domain" "service" {
|
||||
name = var.domain_name
|
||||
autostart = true
|
||||
memory = var.domain_memory
|
||||
vcpu = var.domain_vcpu
|
||||
|
||||
coreos_ignition = libvirt_ignition.ign.id
|
||||
|
||||
disk {
|
||||
volume_id = libvirt_volume.rootfs.id
|
||||
}
|
||||
disk {
|
||||
volume_id = libvirt_volume.data.id
|
||||
}
|
||||
network_interface {
|
||||
network_id = var.domain_network.network_id
|
||||
hostname = var.domain_network.hostname
|
||||
addresses = var.domain_network.addresses
|
||||
mac = var.domain_network.mac_address
|
||||
wait_for_lease = true
|
||||
}
|
||||
console {
|
||||
type = "pty"
|
||||
target_port = "0"
|
||||
target_type = "serial"
|
||||
}
|
||||
graphics {
|
||||
type = "spice"
|
||||
}
|
||||
}
|
38
tofu/service-vm/variables.tf
Normal file
38
tofu/service-vm/variables.tf
Normal file
|
@ -0,0 +1,38 @@
|
|||
variable "domain_name" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "domain_memory" {
|
||||
type = string
|
||||
default = "2048"
|
||||
}
|
||||
|
||||
variable "domain_vcpu" {
|
||||
type = number
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "domain_pool" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "domain_base_volume_id" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "domain_data_volume_size" {
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "domain_ignition_path" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "domain_network" {
|
||||
type = object({
|
||||
network_id = string
|
||||
hostname = string
|
||||
addresses = list(string)
|
||||
mac_address = string
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue