Remove useless data sources, add lxc hook script
This commit is contained in:
parent
57c808c62f
commit
a9caeece85
@ -1,6 +0,0 @@
|
|||||||
data "external" "master_kube" {
|
|
||||||
program = ["sh", "${path.module}/ext/name-gen.sh", "kube", "master"]
|
|
||||||
}
|
|
||||||
data "external" "worker_kube" {
|
|
||||||
program = ["sh", "${path.module}/ext/name-gen.sh", "kube", "worker"]
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
from json import dumps
|
|
||||||
|
|
||||||
start = 666
|
|
||||||
|
|
||||||
name = {
|
|
||||||
'name': start
|
|
||||||
}
|
|
||||||
|
|
||||||
print(dumps(name))
|
|
@ -1,10 +0,0 @@
|
|||||||
from datetime import datetime
|
|
||||||
from json import dumps
|
|
||||||
from sys import argv
|
|
||||||
|
|
||||||
name = argv[1]
|
|
||||||
type = argv[2]
|
|
||||||
timestamp = datetime.now().strftime('%d.%m.%Y-%H:%M:%S')
|
|
||||||
name = f'{name}-{type}-{timestamp}'
|
|
||||||
|
|
||||||
print(dumps({'name': name}))
|
|
@ -1,2 +0,0 @@
|
|||||||
#/bin/sh
|
|
||||||
echo {\"name\":\"$1-$2-`date +'%d.%m.%Y-%H:%M:%S'`\"}
|
|
112
kubes-lxc.tf
112
kubes-lxc.tf
@ -1,18 +1,75 @@
|
|||||||
|
|
||||||
resource "proxmox_virtual_environment_download_file" "latest_alpine" {
|
resource "proxmox_virtual_environment_download_file" "latest_alpine" {
|
||||||
content_type = "vztmpl"
|
content_type = "vztmpl"
|
||||||
datastore_id = "local"
|
datastore_id = var.datastore_id
|
||||||
node_name = "papp-bunt"
|
node_name = var.proxmox_node
|
||||||
url = "http://download.proxmox.com/images/system/alpine-3.20-default_20240908_amd64.tar.xz"
|
url = "http://download.proxmox.com/images/system/alpine-3.20-default_20240908_amd64.tar.xz"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_container" "kube-template" {
|
resource "proxmox_virtual_environment_file" "kube-init" {
|
||||||
description = "Managed by Terraform"
|
content_type = "snippets"
|
||||||
|
datastore_id = var.datastore_id
|
||||||
node_name = var.proxmox_node
|
node_name = var.proxmox_node
|
||||||
vm_id = var.vmid
|
file_mode = "0755"
|
||||||
start_on_boot = "true"
|
source_raw {
|
||||||
|
file_name = "kube-init.sh"
|
||||||
|
data = <<-EOF
|
||||||
|
#!/bin/sh
|
||||||
|
apk update
|
||||||
|
apk upgrade
|
||||||
|
apk add openssh-server
|
||||||
|
rc-update add sshd
|
||||||
|
openrc -s sshd start
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "proxmox_virtual_environment_container" "kube-masters" {
|
||||||
|
# hook_script_file_id = "${var.datastore_id}:snippets/kube-init.sh"
|
||||||
|
vm_id = var.vmid + count.index + 10
|
||||||
|
node_name = var.proxmox_node
|
||||||
|
count = var.master_count
|
||||||
|
depends_on = [
|
||||||
|
proxmox_virtual_environment_download_file.latest_alpine,
|
||||||
|
proxmox_virtual_environment_file.kube-init
|
||||||
|
]
|
||||||
initialization {
|
initialization {
|
||||||
hostname = "kube-template"
|
# hostname = data.external.master_kube.result.name
|
||||||
|
hostname = "kube-master-${tostring(count.index)}.kubes.42069.no"
|
||||||
|
ip_config {
|
||||||
|
ipv4 {
|
||||||
|
address = "dhcp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
user_account {
|
||||||
|
password = var.user_password
|
||||||
|
keys = var.ssh_keys
|
||||||
|
}
|
||||||
|
}
|
||||||
|
network_interface {
|
||||||
|
name = "eth0"
|
||||||
|
}
|
||||||
|
operating_system {
|
||||||
|
template_file_id = proxmox_virtual_environment_download_file.latest_alpine.id
|
||||||
|
type = "alpine"
|
||||||
|
}
|
||||||
|
startup {
|
||||||
|
order = "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "proxmox_virtual_environment_container" "kube-workers" {
|
||||||
|
hook_script_file_id = "${var.datastore_id}:snippets/kube-init.sh"
|
||||||
|
vm_id = var.vmid + 100 + count.index
|
||||||
|
node_name = var.proxmox_node
|
||||||
|
count = var.worker_count
|
||||||
|
depends_on = [
|
||||||
|
proxmox_virtual_environment_download_file.latest_alpine,
|
||||||
|
proxmox_virtual_environment_file.kube-init
|
||||||
|
]
|
||||||
|
initialization {
|
||||||
|
# hostname = data.external.worker_kube.result.name
|
||||||
|
hostname = "kube-worker-${tostring(count.index)}.kubes.42069.no"
|
||||||
ip_config {
|
ip_config {
|
||||||
ipv4 {
|
ipv4 {
|
||||||
address = "dhcp"
|
address = "dhcp"
|
||||||
@ -34,44 +91,3 @@ resource "proxmox_virtual_environment_container" "kube-template" {
|
|||||||
order = "3"
|
order = "3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_container" "kube-masters" {
|
|
||||||
vm_id = var.vmid + count.index + 10
|
|
||||||
node_name = var.proxmox_node
|
|
||||||
count = var.master_count
|
|
||||||
initialization {
|
|
||||||
# hostname = data.external.master_kube.result.name
|
|
||||||
hostname = "kube-master-${tostring(count.index)}.kubes.42069.no"
|
|
||||||
}
|
|
||||||
operating_system {
|
|
||||||
template_file_id = proxmox_virtual_environment_download_file.latest_alpine.id
|
|
||||||
type = "alpine"
|
|
||||||
}
|
|
||||||
startup {
|
|
||||||
order = "1"
|
|
||||||
}
|
|
||||||
provisioner "remote-exec" {
|
|
||||||
inline = [
|
|
||||||
"dnf update -y"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_container" "kube-workers" {
|
|
||||||
vm_id = var.vmid + 100 + count.index
|
|
||||||
node_name = var.proxmox_node
|
|
||||||
count = var.worker_count
|
|
||||||
initialization {
|
|
||||||
# hostname = data.external.worker_kube.result.name
|
|
||||||
hostname = "kube-worker-${tostring(count.index)}.kubes.42069.no"
|
|
||||||
}
|
|
||||||
operating_system {
|
|
||||||
template_file_id = proxmox_virtual_environment_download_file.latest_alpine.id
|
|
||||||
type = "alpine"
|
|
||||||
}
|
|
||||||
provisioner "remote-exec" {
|
|
||||||
inline = [
|
|
||||||
"dnf update -y"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
variable "api_token" {}
|
variable "api_token" {}
|
||||||
|
variable "endpoint" {}
|
||||||
provider "proxmox" {
|
provider "proxmox" {
|
||||||
endpoint = "https://172.31.71.69:8006/api2/json"
|
|
||||||
api_token = var.api_token
|
api_token = var.api_token
|
||||||
|
endpoint = var.endpoint
|
||||||
insecure = true
|
insecure = true
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@ variable "master_count" {
|
|||||||
default = 1
|
default = 1
|
||||||
}
|
}
|
||||||
variable "worker_count" {
|
variable "worker_count" {
|
||||||
default = 2
|
default = 0
|
||||||
|
}
|
||||||
|
variable "datastore_id" {
|
||||||
|
default = "local"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "vmid" {
|
variable "vmid" {
|
||||||
type = number
|
type = number
|
||||||
default = 1000
|
default = 1000
|
||||||
|
Loading…
Reference in New Issue
Block a user