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
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user