patroni-postgresql-cluster (#13)

* Описана инфрастуктура кластера

* Добавлена роль etcd

* Добавлена роль haproxy

* Добавлена роль keepalived

* Добавлена роль ntp_install

* Добавлена роль patroni

* Добавлена групповые переменные

---------

Co-authored-by: Fedor Batonogov <f.batonogov@yandex.ru>
This commit is contained in:
github-actions[bot]
2024-06-18 10:37:21 +03:00
committed by GitHub
parent 5b7920bdca
commit f8fe304cd9
43 changed files with 930 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
# This file is maintained automatically by "tofu init".
# Manual edits may be lost in future updates.
provider "registry.opentofu.org/bpg/proxmox" {
version = "0.60.0"
constraints = ">= 0.53.1"
hashes = [
"h1:ZC+6RI6NKsTB8Y0Lm0onj6N/+k8RZP//GwGqQZN/UVM=",
"zh:0d244b94bdfba501ae285db1d563ad91c393cdb97807377ecdbbc96454e345f7",
"zh:146617d6065d52f512e8e7f9d230e5f8e6e11a67e67c7d8906e212631e53c61e",
"zh:6290bed20fa3e5c070ff867b7a6f2be750c22b9bc97b976a134ab342bdc617ae",
"zh:70d69b7863d0bb5cede73bcb04b81e8ea2be124e19ba854795198302ba04762a",
"zh:7655a8326618cfce8d9e24c1f3fad4a191f80bfc3b3be9a2b7e9169f0c11c05a",
"zh:7700e2443eea1508de880484209f625015b7e8f2c74f615e2c18cc986ee1ffdf",
"zh:96805c02119733f0639084ffd1a194795b153801f91cc22ed4f1cb5487efc035",
"zh:9f8a331cecd7db82cba94e58016ec92d0835fd2f6efc7c5ec46217e4109f1914",
"zh:ae7cdd011e156dd8dadf836c8f1badbc9798c5dbf308313ca29153855bf4f17f",
"zh:b5937d52fdf294b92be3e39581e4c1ecceb89fe614756334c5384102b4551a87",
"zh:b5e11bec8bad9b1ed044d550a8d0a95ca5e94ecd0660a876260909ed42e4dcdb",
"zh:d3f390ae2788240ca3db0aac2d36a01128257649a3e90dd9e600fd8b0c9d9e33",
"zh:d947c22f05af6d81025bf92c5d99fd7db27ee2e5642f4b3a9b1e251673c80656",
"zh:dfeed9507c83d7d4b25539c010d04bd6de12396f15d180a15119b923b3b49fb5",
"zh:f26e0763dbe6a6b2195c94b44696f2110f7f55433dc142839be16b9697fa5597",
]
}

View File

@@ -0,0 +1,94 @@
variable "etcd_vms" {
type = list(object({
name = string
address = string
node_name = string
}))
default = [
{
name = "etcd-01"
address = "10.0.75.114/24"
node_name = "pve-01"
},
{
name = "etcd-02"
address = "10.0.75.115/24"
node_name = "pve-02"
}
]
}
# Создание виртуальных машин
resource "proxmox_virtual_environment_vm" "etcd" {
for_each = { for vm in var.etcd_vms : vm.name => vm }
name = each.value.name
migrate = true
description = "Managed by OpenTofu"
tags = ["etcd"]
on_boot = true
node_name = each.value.node_name
clone {
vm_id = "2404"
node_name = "pve-01"
retries = 3
}
agent {
enabled = true
}
operating_system {
type = "l26"
}
cpu {
cores = 2
type = "host"
numa = true
}
memory {
dedicated = 2048
}
vga {
memory = 4
type = "serial0"
}
disk {
size = "20"
interface = "virtio0"
datastore_id = "proxmox-data-01"
file_format = "raw"
}
network_device {
bridge = "vmbr0"
model = "virtio"
}
initialization {
datastore_id = "proxmox-data-01"
ip_config {
ipv4 {
address = each.value.address
gateway = "10.0.75.1"
}
}
dns {
servers = [
"10.0.75.65",
"10.0.75.66"
]
}
user_account {
username = "infra"
keys = [
var.ssh_public_key
]
}
}
}

View File

@@ -0,0 +1,99 @@
variable "patroni_vms" {
type = list(object({
name = string
address = string
node_name = string
}))
default = [
{
name = "patroni-postgresql-01"
address = "10.0.75.111/24"
node_name = "pve-01"
},
{
name = "patroni-postgresql-02"
address = "10.0.75.112/24"
node_name = "pve-02"
},
{
name = "patroni-postgresql-03" # Исправлено имя
address = "10.0.75.113/24"
node_name = "pve-02"
}
]
}
# Создание виртуальных машин
resource "proxmox_virtual_environment_vm" "patroni" {
for_each = { for vm in var.patroni_vms : vm.name => vm }
name = each.value.name
migrate = true
description = "Managed by OpenTofu"
tags = ["patroni", "postgresql"]
on_boot = true
node_name = each.value.node_name
clone {
vm_id = "2404"
node_name = "pve-01"
retries = 3
}
agent {
enabled = true
}
operating_system {
type = "l26"
}
cpu {
cores = 2
type = "host"
numa = true
}
memory {
dedicated = 2048
}
vga {
memory = 4
type = "serial0"
}
disk {
size = "20"
interface = "virtio0"
datastore_id = "proxmox-data-01"
file_format = "raw"
}
network_device {
bridge = "vmbr0"
model = "virtio"
}
initialization {
datastore_id = "proxmox-data-01"
ip_config {
ipv4 {
address = each.value.address
gateway = "10.0.75.1"
}
}
dns {
servers = [
"10.0.75.65",
"10.0.75.66"
]
}
user_account {
username = "infra"
keys = [
var.ssh_public_key
]
}
}
}

View File

@@ -0,0 +1,17 @@
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = ">= 0.60.0"
}
}
}
provider "proxmox" {
endpoint = var.virtual_environment_endpoint
api_token = var.virtual_environment_api_token
insecure = true
ssh {
agent = false
}
}

View File

@@ -0,0 +1,3 @@
virtual_environment_api_token = "root@pam!for-terraform-provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
virtual_environment_endpoint = "https://x.x.x.x:8006/"
ssh_public_key = "ssh-rsa ..."

View File

@@ -0,0 +1,14 @@
variable "virtual_environment_endpoint" {
type = string
description = "The endpoint for the Proxmox Virtual Environment API (example: https://host:port)"
}
variable "virtual_environment_api_token" {
type = string
description = "The api roken the Proxmox Virtual Environment API (example: root@pam!for-terraform-provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)"
}
variable "ssh_public_key" {
type = string
description = "SSH Puclic key for VMs (example: ssh-rsa ...)"
}