initial commit

This commit is contained in:
2026-06-14 14:21:09 +07:00
commit 054835e2a7
17 changed files with 771 additions and 0 deletions

2
terraform/.env.example Normal file
View File

@@ -0,0 +1,2 @@
export TF_VAR_proxmox_endpoint=https://<proxmox-node-ip>:8006
export TF_VAR_proxmox_api_token=terraform@pve!terraform=<token-secret>

10
terraform/.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
.env
.terraform/
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
*.tfstate
*.tfstate.*
k8s_terraform
k8s_terraform.pub
*.tfvars.local

8
terraform/cloud_image.tf Normal file
View File

@@ -0,0 +1,8 @@
resource "proxmox_download_file" "centos10" {
content_type = "import"
datastore_id = "local"
node_name = var.proxmox_node
url = "https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-10-latest.x86_64.qcow2"
file_name = "centos-stream-10-cloud.qcow2"
overwrite = false
}

14
terraform/main.tf Normal file
View File

@@ -0,0 +1,14 @@
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "~> 0.107"
}
}
}
provider "proxmox" {
endpoint = var.proxmox_endpoint
api_token = var.proxmox_api_token
insecure = true
}

11
terraform/outputs.tf Normal file
View File

@@ -0,0 +1,11 @@
output "master_ip" {
value = "192.168.1.31"
}
output "worker_ips" {
value = { for k, v in proxmox_virtual_environment_vm.workers : k => v.initialization[0].ip_config[0].ipv4[0].address }
}
output "ssh_command" {
value = "ssh -i ${path.module}/k8s_terraform cloud-user@192.168.1.31"
}

View File

@@ -0,0 +1,5 @@
proxmox_endpoint = "https://192.168.1.18:8006"
proxmox_node = "proxmox03"
proxmox_pool = "IaC"
gateway = "192.168.1.1"
dns_server = "192.168.1.1"

24
terraform/variables.tf Normal file
View File

@@ -0,0 +1,24 @@
variable "proxmox_endpoint" {
description = "Proxmox API endpoint URL"
}
variable "proxmox_api_token" {
description = "Proxmox API token (user@realm!tokenid=secret)"
sensitive = true
}
variable "proxmox_node" {
default = "proxmox03"
}
variable "proxmox_pool" {
default = "IaC"
}
variable "gateway" {
default = "192.168.1.1"
}
variable "dns_server" {
default = "192.168.1.1"
}

121
terraform/vms.tf Normal file
View File

@@ -0,0 +1,121 @@
resource "proxmox_virtual_environment_vm" "master" {
name = "master01"
vm_id = 131
node_name = var.proxmox_node
pool_id = var.proxmox_pool
stop_on_destroy = true
cpu {
cores = 2
type = "host"
}
memory {
dedicated = 8192
}
scsi_hardware = "virtio-scsi-single"
disk {
datastore_id = "xpen"
import_from = proxmox_download_file.centos10.id
interface = "scsi0"
iothread = true
size = 100
}
network_device {
bridge = "vmbr0"
model = "virtio"
}
boot_order = ["scsi0"]
agent {
enabled = true
}
initialization {
datastore_id = "local"
ip_config {
ipv4 {
address = "192.168.1.31/24"
gateway = var.gateway
}
}
dns {
servers = [var.dns_server]
}
user_account {
username = "cloud-user"
keys = [trimspace(file("${path.module}/k8s_terraform.pub"))]
}
}
}
resource "proxmox_virtual_environment_vm" "workers" {
for_each = {
worker01 = { vm_id = 135, ip = "192.168.1.35" }
worker02 = { vm_id = 136, ip = "192.168.1.36" }
worker03 = { vm_id = 137, ip = "192.168.1.37" }
}
name = each.key
vm_id = each.value.vm_id
node_name = var.proxmox_node
pool_id = var.proxmox_pool
stop_on_destroy = true
cpu {
cores = 2
type = "host"
}
memory {
dedicated = 12288
}
scsi_hardware = "virtio-scsi-single"
disk {
datastore_id = "xpen"
import_from = proxmox_download_file.centos10.id
interface = "scsi0"
iothread = true
size = 100
}
network_device {
bridge = "vmbr0"
model = "virtio"
}
boot_order = ["scsi0"]
agent {
enabled = true
}
initialization {
datastore_id = "local"
ip_config {
ipv4 {
address = "${each.value.ip}/24"
gateway = var.gateway
}
}
dns {
servers = [var.dns_server]
}
user_account {
username = "cloud-user"
keys = [trimspace(file("${path.module}/k8s_terraform.pub"))]
}
}
}