init
This commit is contained in:
36
terraform/stacks/proxmox/vm/cloud-init/user-data.yaml.tpl
Normal file
36
terraform/stacks/proxmox/vm/cloud-init/user-data.yaml.tpl
Normal file
@@ -0,0 +1,36 @@
|
||||
#cloud-config
|
||||
hostname: ${hostname}
|
||||
manage_etc_hosts: true
|
||||
|
||||
package_update: true
|
||||
package_upgrade: true
|
||||
|
||||
packages:
|
||||
- parted
|
||||
|
||||
# user
|
||||
users:
|
||||
- name: "adminuser"
|
||||
groups: sudo
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
lock_passwd: false
|
||||
passwd: "$6$qL4GPP3AhSodbF9U$Lu4.VSpCSlAVPNIZyPNme0AH8HhbVYE6SAm3P3Er7KSLIYydj799tZBz/n6NRzzRYhyQh9a4h8m8WCbjw2nXg1"
|
||||
shell: /bin/bash
|
||||
ssh_authorized_keys:
|
||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBcTy4Zcj3MHkW7XvnZhakl64vZXnjzDJymYlo+Ax8FM dev-kyiv01-vm-default-main-01-adminuser"
|
||||
|
||||
ssh_pwauth: false
|
||||
|
||||
runcmd:
|
||||
- |
|
||||
set -euxo pipefail
|
||||
|
||||
# растянуть extended + LVM partition до конца диска
|
||||
growpart /dev/sda 2 || true
|
||||
growpart /dev/sda 5 || true
|
||||
parted -s /dev/sda "resizepart 2 100%" "resizepart 5 100%" || true
|
||||
partprobe /dev/sda || true
|
||||
|
||||
# растянуть PV -> LV(root) -> FS
|
||||
pvresize /dev/sda5
|
||||
lvextend -l +100%FREE -r /dev/vg0/root
|
||||
72
terraform/stacks/proxmox/vm/locals.tf
Normal file
72
terraform/stacks/proxmox/vm/locals.tf
Normal file
@@ -0,0 +1,72 @@
|
||||
locals {
|
||||
vms = {
|
||||
dev_kyiv01_vm_dns_main_01 = {
|
||||
name = "dev-kyiv01-vm-dns-main-01"
|
||||
cpu = 2
|
||||
cpu_type = "x86-64-v2"
|
||||
memory = 3072
|
||||
disk_size = 20
|
||||
mac = "02:7A:4C:11:90:64"
|
||||
}
|
||||
|
||||
dev_kyiv01_vm_ntp_main_01 = {
|
||||
name = "dev-kyiv01-vm-ntp-main-01"
|
||||
cpu = 1
|
||||
cpu_type = "x86-64-v2"
|
||||
memory = 2048
|
||||
disk_size = 8
|
||||
mac = "02:7A:4C:11:90:65"
|
||||
}
|
||||
|
||||
dev_kyiv01_vm_ceph_main_01 = {
|
||||
name = "dev-kyiv01-vm-ceph-main-01"
|
||||
cpu = 2
|
||||
cpu_type = "x86-64-v2"
|
||||
memory = 4096
|
||||
disk_size = 30
|
||||
mac = "02:7A:4C:11:90:66"
|
||||
osd_storage = "ceph-osd"
|
||||
osd_disks = [150, 150]
|
||||
}
|
||||
|
||||
dev_kyiv01_vm_ceph_main_02 = {
|
||||
name = "dev-kyiv01-vm-ceph-main-02"
|
||||
cpu = 2
|
||||
cpu_type = "x86-64-v2"
|
||||
memory = 4096
|
||||
disk_size = 30
|
||||
mac = "02:7A:4C:11:90:67"
|
||||
osd_storage = "ceph-osd"
|
||||
osd_disks = [150, 150]
|
||||
}
|
||||
|
||||
dev_kyiv01_vm_ceph_main_03 = {
|
||||
name = "dev-kyiv01-vm-ceph-main-03"
|
||||
cpu = 2
|
||||
cpu_type = "x86-64-v2"
|
||||
memory = 4096
|
||||
disk_size = 30
|
||||
mac = "02:7A:4C:11:90:68"
|
||||
osd_storage = "ceph-osd"
|
||||
osd_disks = [150, 150]
|
||||
}
|
||||
|
||||
dev_kyiv01_vm_k8s_master_01 = {
|
||||
name = "dev-kyiv01-vm-k8s-master-01"
|
||||
cpu = 2
|
||||
cpu_type = "x86-64-v2"
|
||||
memory = 4096
|
||||
disk_size = 40
|
||||
mac = "02:7A:4C:11:90:69"
|
||||
}
|
||||
|
||||
dev_kyiv01_vm_k8s_worker_01 = {
|
||||
name = "dev-kyiv01-vm-k8s-worker-01"
|
||||
cpu = 4
|
||||
cpu_type = "x86-64-v2"
|
||||
memory = 8192
|
||||
disk_size = 60
|
||||
mac = "02:7A:4C:11:90:6A"
|
||||
}
|
||||
}
|
||||
}
|
||||
41
terraform/stacks/proxmox/vm/main.tf
Normal file
41
terraform/stacks/proxmox/vm/main.tf
Normal file
@@ -0,0 +1,41 @@
|
||||
# 1) Для каждой VM создаём snippet user-data (cloud-init)
|
||||
resource "proxmox_virtual_environment_file" "user_data" {
|
||||
for_each = local.vms
|
||||
|
||||
content_type = "snippets"
|
||||
datastore_id = var.snippets_storage
|
||||
node_name = var.target_node
|
||||
|
||||
source_raw {
|
||||
data = templatefile("${path.module}/cloud-init/user-data.yaml.tpl", {
|
||||
hostname = each.value.name
|
||||
})
|
||||
|
||||
file_name = "user-data-${each.value.name}.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
# 2) Создаём VM-ки и подцепляем user-data файл
|
||||
module "vm" {
|
||||
source = "../../../modules/proxmox/vm"
|
||||
for_each = local.vms
|
||||
|
||||
name = each.value.name
|
||||
target_node = var.target_node
|
||||
template_id = var.template_id
|
||||
|
||||
cpu = each.value.cpu
|
||||
cpu_type = try(each.value.cpu_type, "qemu64")
|
||||
memory = each.value.memory
|
||||
|
||||
disk_size = each.value.disk_size
|
||||
storage = var.storage
|
||||
bridge = var.bridge
|
||||
|
||||
osd_storage = try(each.value.osd_storage, null)
|
||||
osd_disks = try(each.value.osd_disks, [])
|
||||
|
||||
user_data_file_id = proxmox_virtual_environment_file.user_data[each.key].id
|
||||
|
||||
mac_address = each.value.mac
|
||||
}
|
||||
17
terraform/stacks/proxmox/vm/providers.tf
Normal file
17
terraform/stacks/proxmox/vm/providers.tf
Normal file
@@ -0,0 +1,17 @@
|
||||
provider "proxmox" {
|
||||
endpoint = var.pm_api_url
|
||||
api_token = var.pm_api_token
|
||||
insecure = true
|
||||
|
||||
ssh {
|
||||
agent = false
|
||||
username = "root"
|
||||
private_key = file("/workspaces/infrastructure/.ssh/dev-kyiv01-proxmox-main-01")
|
||||
|
||||
node {
|
||||
name = "proxmox-main-kyiv-01"
|
||||
address = "176.36.225.227"
|
||||
port = 25105
|
||||
}
|
||||
}
|
||||
}
|
||||
50
terraform/stacks/proxmox/vm/variables.tf
Normal file
50
terraform/stacks/proxmox/vm/variables.tf
Normal file
@@ -0,0 +1,50 @@
|
||||
variable "pm_api_url" {
|
||||
type = string
|
||||
description = "Proxmox API endpoint, e.g. https://proxmox:8006/api2/json"
|
||||
}
|
||||
|
||||
variable "pm_api_token" {
|
||||
type = string
|
||||
description = "Proxmox API token: root@pam!terraform=..."
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "pm_user" {
|
||||
type = string
|
||||
description = "SSH username for Proxmox node"
|
||||
default = "root"
|
||||
}
|
||||
|
||||
variable "pm_password" {
|
||||
type = string
|
||||
description = "SSH password for Proxmox node"
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "target_node" {
|
||||
type = string
|
||||
description = "Target Proxmox node name"
|
||||
}
|
||||
|
||||
variable "template_id" {
|
||||
type = number
|
||||
description = "Template VM ID to clone from"
|
||||
}
|
||||
|
||||
variable "storage" {
|
||||
type = string
|
||||
description = "Default datastore for OS disk"
|
||||
default = "local-lvm"
|
||||
}
|
||||
|
||||
variable "bridge" {
|
||||
type = string
|
||||
description = "Default VM bridge"
|
||||
default = "vmbr0"
|
||||
}
|
||||
|
||||
variable "snippets_storage" {
|
||||
type = string
|
||||
description = "Datastore where 'snippets' content is enabled (usually 'local')"
|
||||
default = "local"
|
||||
}
|
||||
10
terraform/stacks/proxmox/vm/versions.tf
Normal file
10
terraform/stacks/proxmox/vm/versions.tf
Normal file
@@ -0,0 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">= 1.6"
|
||||
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "bpg/proxmox"
|
||||
version = "0.86.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user