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'`\"}
|
114
kubes-lxc.tf
114
kubes-lxc.tf
@ -1,18 +1,75 @@
|
||||
|
||||
resource "proxmox_virtual_environment_download_file" "latest_alpine" {
|
||||
content_type = "vztmpl"
|
||||
datastore_id = "local"
|
||||
node_name = "papp-bunt"
|
||||
datastore_id = var.datastore_id
|
||||
node_name = var.proxmox_node
|
||||
url = "http://download.proxmox.com/images/system/alpine-3.20-default_20240908_amd64.tar.xz"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_container" "kube-template" {
|
||||
description = "Managed by Terraform"
|
||||
node_name = var.proxmox_node
|
||||
vm_id = var.vmid
|
||||
start_on_boot = "true"
|
||||
resource "proxmox_virtual_environment_file" "kube-init" {
|
||||
content_type = "snippets"
|
||||
datastore_id = var.datastore_id
|
||||
node_name = var.proxmox_node
|
||||
file_mode = "0755"
|
||||
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 {
|
||||
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 {
|
||||
ipv4 {
|
||||
address = "dhcp"
|
||||
@ -34,44 +91,3 @@ resource "proxmox_virtual_environment_container" "kube-template" {
|
||||
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 "endpoint" {}
|
||||
provider "proxmox" {
|
||||
endpoint = "https://172.31.71.69:8006/api2/json"
|
||||
api_token = var.api_token
|
||||
endpoint = var.endpoint
|
||||
insecure = true
|
||||
}
|
||||
|
@ -3,9 +3,11 @@ variable "master_count" {
|
||||
default = 1
|
||||
}
|
||||
variable "worker_count" {
|
||||
default = 2
|
||||
default = 0
|
||||
}
|
||||
variable "datastore_id" {
|
||||
default = "local"
|
||||
}
|
||||
|
||||
variable "vmid" {
|
||||
type = number
|
||||
default = 1000
|
||||
|
Loading…
x
Reference in New Issue
Block a user