Terraform rules working
This commit is contained in:
127
terraform/main.tf
Normal file
127
terraform/main.tf
Normal file
@@ -0,0 +1,127 @@
|
||||
resource "proxmox_vm_qemu" "proxmox_vm_master" {
|
||||
count = var.num_k3s_masters
|
||||
name = "k3s-master-${count.index}"
|
||||
target_node = var.pm_node_name
|
||||
clone = var.template_vm_name # The name of the template
|
||||
agent = 1
|
||||
cores = 2
|
||||
memory = var.num_k3s_masters_mem
|
||||
boot = "order=scsi0" # has to be the same as the OS disk of the template
|
||||
scsihw = "virtio-scsi-single"
|
||||
vm_state = "running"
|
||||
automatic_reboot = true
|
||||
|
||||
# Cloud-Init configuration
|
||||
cicustom = "vendor=local:snippets/qemu-guest-agent.yml" # /var/lib/vz/snippets/qemu-guest-agent.yml
|
||||
ciupgrade = true
|
||||
nameserver = "1.1.1.1 8.8.8.8"
|
||||
ipconfig0 = "ip=${var.master_ips[count.index]}/${var.networkrange},gw=${var.gateway}"
|
||||
skip_ipv6 = true
|
||||
ciuser = "debian"
|
||||
cipassword = ""
|
||||
sshkeys = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKXXnm9Hl4fPCt/Xjd/8E5tKY+edtM/BvdMOXpx40oWG iac@proxmox.vadzik-iot.ru"
|
||||
|
||||
# Most cloud-init images require a serial device for their display
|
||||
serial {
|
||||
id = 0
|
||||
}
|
||||
|
||||
disks {
|
||||
scsi {
|
||||
scsi0 {
|
||||
disk {
|
||||
storage = "flash-VM"
|
||||
size = "8G"
|
||||
}
|
||||
}
|
||||
}
|
||||
ide {
|
||||
# Some images require a cloud-init disk on the IDE controller, others on the SCSI or SATA controller
|
||||
ide1 {
|
||||
cloudinit {
|
||||
storage = "flash-VM"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
network {
|
||||
id = 0
|
||||
bridge = "vmbr2"
|
||||
model = "virtio"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resource "proxmox_vm_qemu" "proxmox_vm_workers" {
|
||||
count = var.num_k3s_nodes
|
||||
name = "k3s-worker-${count.index}"
|
||||
target_node = var.pm_node_name
|
||||
clone = var.template_vm_name
|
||||
os_type = "cloud-init"
|
||||
agent = 1
|
||||
cores = 4
|
||||
memory = var.num_k3s_nodes_mem
|
||||
boot = "order=scsi0" # has to be the same as the OS disk of the template
|
||||
scsihw = "virtio-scsi-single"
|
||||
vm_state = "running"
|
||||
automatic_reboot = true
|
||||
|
||||
# Cloud-Init configuration
|
||||
cicustom = "vendor=local:snippets/qemu-guest-agent.yml" # /var/lib/vz/snippets/qemu-guest-agent.yml
|
||||
ciupgrade = true
|
||||
nameserver = "1.1.1.1 8.8.8.8"
|
||||
ipconfig0 = "ip=${var.worker_ips[count.index]}/${var.networkrange},gw=${var.gateway}"
|
||||
skip_ipv6 = true
|
||||
ciuser = "debian"
|
||||
cipassword = ""
|
||||
sshkeys = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKXXnm9Hl4fPCt/Xjd/8E5tKY+edtM/BvdMOXpx40oWG iac@proxmox.vadzik-iot.ru"
|
||||
|
||||
# Most cloud-init images require a serial device for their display
|
||||
serial {
|
||||
id = 0
|
||||
}
|
||||
|
||||
disks {
|
||||
scsi {
|
||||
scsi0 {
|
||||
disk {
|
||||
storage = "flash-VM"
|
||||
size = "8G"
|
||||
}
|
||||
}
|
||||
}
|
||||
ide {
|
||||
# Some images require a cloud-init disk on the IDE controller, others on the SCSI or SATA controller
|
||||
ide1 {
|
||||
cloudinit {
|
||||
storage = "flash-VM"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
network {
|
||||
id = 0
|
||||
bridge = "vmbr2"
|
||||
model = "virtio"
|
||||
}
|
||||
}
|
||||
|
||||
data "template_file" "k8s" {
|
||||
template = file("./templates/inventory.tpl")
|
||||
vars = {
|
||||
k3s_master_ip = "${join("\n", [for instance in proxmox_vm_qemu.proxmox_vm_master : join("", [instance.default_ipv4_address, " ansible_ssh_private_key_file=", var.pvt_key])])}"
|
||||
k3s_node_ip = "${join("\n", [for instance in proxmox_vm_qemu.proxmox_vm_workers : join("", [instance.default_ipv4_address, " ansible_ssh_private_key_file=", var.pvt_key])])}"
|
||||
}
|
||||
}
|
||||
|
||||
resource "local_file" "k8s_file" {
|
||||
content = data.template_file.k8s.rendered
|
||||
filename = "../ansible/inventory/k3s-cluster/hosts.ini"
|
||||
}
|
||||
|
||||
resource "local_file" "var_file" {
|
||||
source = "../ansible/inventory/group_vars/all.yml"
|
||||
filename = "../ansible/inventory/k3s-cluster/group_vars/all.yml"
|
||||
}
|
||||
Reference in New Issue
Block a user