Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions VM/Proxmox/Debian/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
k3s_version: v1.22.3+k3s1
ansible_user: root
systemd_dir: /etc/systemd/system
master_ip: "{{ hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) }}"
extra_server_args: ""
extra_agent_args: ""
61 changes: 61 additions & 0 deletions VM/Proxmox/Debian/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

module "node" {
count = var.provisionning_debian_kubernetes_nodes
source = "QJoly/proxmox/module"
version = "0.0.1"
node_name = "kube-${count.index}-tf"
node_target = var.hypervisor_proxmox_node
node_qemuga = 1
node_pool = var.hypervisor_proxmox_vm_pool
node_size_disk = "${var.vmtemplate_debian_disk_size}M"
node_bootauto = true
node_template = var.vmtemplate_debian_name
node_storage_disk = var.hypervisor_proxmox_vm_storage
node_network_host = var.hypervisor_proxmox_vm_network
node_notes = "Super-VM for the customer No 01"
node_cpu = var.provisionning_debian_cpu
node_memory = var.provisionning_debian_memory
}

resource "local_file" "inventory" {
filename = "./inventory.ini"
content = <<_EOF
[master]
${module.node[0].node_name} ansible_host=${module.node[0].node_ip}
%{if length(module.node) > 1}
[node]
%{for item in slice(module.node.*, 1, length(module.node))~}
${item.node_name} ansible_host=${item.node_ip}
%{endfor}
%{endif}
[k3s_cluster:children]
master
node
_EOF
depends_on = [module.node]
}

resource "local_file" "master" {
filename = "../../../artifacts/master"
content = <<_EOF
${module.node[0].node_ip}
_EOF

depends_on = [module.node]
}

resource "null_resource" "playbooks" {
count = var.provisionning_debian_kubernetes_enabled ? 1 : 0

depends_on = [module.node, local_file.inventory]

provisioner "local-exec" {
when = create
command = "ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --timeout 30 -i inventory.ini ${path.cwd}/../../Ansible/set_hostname.yml -v"
}

provisioner "local-exec" {
when = create
command = "ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --timeout 30 -i inventory.ini ${path.cwd}/../../Ansible/k3s/site.yml -v -e ansible_user=utilisateur"
}
}
16 changes: 16 additions & 0 deletions VM/Proxmox/Debian/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = "2.9.14"
}
}
}

provider "proxmox" {
pm_api_url = var.hypervisor_proxmox_node_url
pm_user = var.hypervisor_proxmox_username
pm_password = var.hypervisor_proxmox_password
pm_tls_insecure = "true"
pm_parallel = 3
}
77 changes: 77 additions & 0 deletions VM/Proxmox/Debian/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
variable "provisionning_debian_memory" {
type = number
default = 1024
description = "Quantity of RAM (in Mo) for each node."
}

variable "provisionning_debian_cpu" {
type = number
default = 1
description = "Number of CPU for each node."
}

variable "hypervisor_proxmox_vm_network" {
type = string
default = "vmbr0"
description = "Network interface that will be used as bridge"
}

variable "provisionning_debian_kubernetes_nodes" {
type = string
default = 2
description = "Number of nodes that will be created."
}

variable "provisionning_debian_kubernetes_enabled" {
type = bool
default = false
description = "If true, Terrafom will run the Ansible Playbook that install the cluster"
}

variable "vmtemplate_debian_name" {
type = string
default = "Debian"
description = "VM that will be cloned."
}

variable "hypervisor_proxmox_vm_storage" {
type = string
default = "local-zfs"
description = "Storage that will store the VM."
}

variable "vmtemplate_debian_disk_size" {
type = string
default = "32G"
description = "Storage that will store the VM."
}

variable "hypervisor_proxmox_node" {
type = string
default = "pve"
description = "Proxmox Node."
}

variable "hypervisor_proxmox_node_url" {
type = string
default = "http://192.168.1.100:8006/api2/json"
description = "Proxmox URL"
}

variable "hypervisor_proxmox_username" {
type = string
default = "root@pam"
description = "Proxmox Username"
}

variable "hypervisor_proxmox_password" {
type = string
default = "RootPassword"
description = "Proxmox Pass"
}

variable "hypervisor_proxmox_vm_pool" {
type = string
default = ""
description = "Proxmox pool"
}