init: add initial code
This commit is contained in:
@@ -0,0 +1,117 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
proxmox = {
|
||||||
|
source = "bpg/proxmox"
|
||||||
|
version = "~> 0.78.2"
|
||||||
|
}
|
||||||
|
technitium = {
|
||||||
|
source = "kenske/technitium"
|
||||||
|
version = "~> 0.2"
|
||||||
|
}
|
||||||
|
uptimekuma = {
|
||||||
|
source = "breml/uptimekuma"
|
||||||
|
version = "~> 0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data "terraform_remote_state" "uptime" {
|
||||||
|
backend = "http"
|
||||||
|
|
||||||
|
config = {
|
||||||
|
address = "https://git.itlab-ffeks.dnu.edu.ua/api/packages/infrastructure/terraform/state/uptime-kuma-base-infrastructure-main"
|
||||||
|
username = "admin"
|
||||||
|
password = var.gitea_password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
is_prod = var.environment == "prod" || var.environment == "production"
|
||||||
|
|
||||||
|
env_tag_id = local.is_prod ? data.terraform_remote_state.uptime.outputs.tag_production_id : data.terraform_remote_state.uptime.outputs.tag_staging_id
|
||||||
|
|
||||||
|
ip_only = split("/", var.ip_address)[0]
|
||||||
|
|
||||||
|
monitor_dnu_dns = var.monitor_dnu_dns != null ? var.monitor_dnu_dns : (local.is_prod ? true : false)
|
||||||
|
}
|
||||||
|
|
||||||
|
# 1. Proxmox VM Creation
|
||||||
|
module "vm" {
|
||||||
|
source = "git::https://git.itlab-ffeks.dnu.edu.ua/infrastructure/proxmox-vm.git"
|
||||||
|
|
||||||
|
vm_name = var.vm_name
|
||||||
|
vm_id = var.vm_id
|
||||||
|
ip_address = var.ip_address
|
||||||
|
ssh_public_keys = var.ssh_public_keys
|
||||||
|
gateway = var.gateway
|
||||||
|
node_name = var.node_name
|
||||||
|
template_id = var.template_id
|
||||||
|
cpu_cores = var.cpu_cores
|
||||||
|
memory_mb = var.memory_mb
|
||||||
|
bridge = var.bridge
|
||||||
|
}
|
||||||
|
|
||||||
|
# 2. Internal DNS Record Creation
|
||||||
|
module "dns_record" {
|
||||||
|
source = "git::https://git.itlab-ffeks.dnu.edu.ua/infrastructure/dns-record.git"
|
||||||
|
subdomain = var.subdomain
|
||||||
|
}
|
||||||
|
|
||||||
|
# 3. Uptime Kuma: Internal DNS Monitor
|
||||||
|
resource "uptimekuma_monitor_dns" "internal_dns" {
|
||||||
|
name = "${var.service_name} Internal DNS Monitoring (${var.environment})"
|
||||||
|
hostname = "${var.subdomain}.itlab-ffeks.dnu.edu.ua"
|
||||||
|
dns_resolve_server = "212.3.125.242"
|
||||||
|
parent = data.terraform_remote_state.uptime.outputs.monitor_group_internal_dns_id
|
||||||
|
|
||||||
|
tags = [
|
||||||
|
{
|
||||||
|
tag_id = local.env_tag_id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag_id = data.terraform_remote_state.uptime.outputs.tag_dns_id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# 4. Uptime Kuma: DNU DNS Monitor (Configurable, default true for prod, false for staging)
|
||||||
|
resource "uptimekuma_monitor_dns" "dnu_dns" {
|
||||||
|
count = local.monitor_dnu_dns ? 1 : 0
|
||||||
|
name = "${var.service_name} DNU DNS Monitoring (${var.environment})"
|
||||||
|
hostname = "${var.subdomain}.itlab-ffeks.dnu.edu.ua"
|
||||||
|
parent = data.terraform_remote_state.uptime.outputs.monitor_group_dnu_dns_id
|
||||||
|
|
||||||
|
tags = [
|
||||||
|
{
|
||||||
|
tag_id = local.env_tag_id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag_id = data.terraform_remote_state.uptime.outputs.tag_dns_id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# 5. Uptime Kuma: VM Ping Monitor
|
||||||
|
resource "uptimekuma_monitor_ping" "ping" {
|
||||||
|
name = "Ping ${var.service_name} (${var.environment})"
|
||||||
|
hostname = local.ip_only
|
||||||
|
parent = data.terraform_remote_state.uptime.outputs.monitor_group_ping_id
|
||||||
|
|
||||||
|
tags = [
|
||||||
|
{
|
||||||
|
tag_id = local.env_tag_id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# 6. Uptime Kuma: HTTP health check Monitor (Configurable path, default "/")
|
||||||
|
resource "uptimekuma_monitor_http" "http" {
|
||||||
|
name = "${var.service_name} HTTP Monitoring (${var.environment})"
|
||||||
|
url = "http://${local.ip_only}${var.http_health_check_path}"
|
||||||
|
|
||||||
|
tags = [
|
||||||
|
{
|
||||||
|
tag_id = local.env_tag_id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
output "internal_dns_monitor_id" {
|
||||||
|
description = "The ID of the internal DNS Uptime Kuma monitor"
|
||||||
|
value = uptimekuma_monitor_dns.internal_dns.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "dnu_dns_monitor_id" {
|
||||||
|
description = "The ID of the DNU DNS Uptime Kuma monitor"
|
||||||
|
value = length(uptimekuma_monitor_dns.dnu_dns) > 0 ? uptimekuma_monitor_dns.dnu_dns[0].id : null
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ping_monitor_id" {
|
||||||
|
description = "The ID of the ping Uptime Kuma monitor"
|
||||||
|
value = uptimekuma_monitor_ping.ping.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "http_monitor_id" {
|
||||||
|
description = "The ID of the HTTP Uptime Kuma monitor"
|
||||||
|
value = uptimekuma_monitor_http.http.id
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
variable "environment" {
|
||||||
|
description = "The target environment (e.g., staging, prod)"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "service_name" {
|
||||||
|
description = "The name of the service (e.g., s3)"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "subdomain" {
|
||||||
|
description = "The subdomain prefix for the environment"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_id" {
|
||||||
|
description = "Proxmox VM ID"
|
||||||
|
type = number
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_name" {
|
||||||
|
description = "Name of the VM in Proxmox UI and internal OS hostname"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ip_address" {
|
||||||
|
description = "Static IPv4 address in CIDR format (e.g., 10.1.1.2/8)"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_public_keys" {
|
||||||
|
description = "List of public SSH keys for the admin user"
|
||||||
|
type = list(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "gateway" {
|
||||||
|
description = "Network gateway IP address"
|
||||||
|
type = string
|
||||||
|
default = "10.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "node_name" {
|
||||||
|
description = "Proxmox node name"
|
||||||
|
type = string
|
||||||
|
default = "itlab-ffeks"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "template_id" {
|
||||||
|
description = "ID of the VM template to clone"
|
||||||
|
type = number
|
||||||
|
default = 205
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "cpu_cores" {
|
||||||
|
description = "Number of CPU cores"
|
||||||
|
type = number
|
||||||
|
default = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "memory_mb" {
|
||||||
|
description = "RAM size in MB"
|
||||||
|
type = number
|
||||||
|
default = 2048
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "bridge" {
|
||||||
|
description = "Network bridge interface"
|
||||||
|
type = string
|
||||||
|
default = "vmbr1"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "monitor_dnu_dns" {
|
||||||
|
description = "Enable monitoring of DNU DNS (if null, defaults to true for prod and false for staging)"
|
||||||
|
type = bool
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "http_health_check_path" {
|
||||||
|
description = "The path for the HTTP health check monitor"
|
||||||
|
type = string
|
||||||
|
default = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "gitea_password" {
|
||||||
|
description = "API Token/Password for Gitea remote HTTP state access"
|
||||||
|
type = string
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user