feat(terraform): remove websites module and add m3uproxy and nginx modules

- Deleted the websites module from the Terraform configuration.
- Introduced a new m3uproxy module with resources for Kubernetes namespace, secrets, config maps, deployments, services, and cron jobs.
- Added configuration files for m3uproxy, including JSON and playlist resources.
- Created a new nginx module with resources for Kubernetes namespace, services, config maps, deployments, and ingress.
- Added necessary variables for both m3uproxy and nginx modules.
- Updated provider configurations for m3uproxy and nginx modules to specify required versions.
This commit is contained in:
2025-04-27 19:40:16 +02:00
parent 654cf500f9
commit 58fb1ea167
20 changed files with 192 additions and 68 deletions
+37
View File
@@ -0,0 +1,37 @@
module "websites" {
source = "../modules/nginx"
persistent_folder = local.persistent_folder
primary_domain = local.primary_domain
websites = local.websites
}
module "rustdesk" {
source = "../modules/rustdesk"
persistent_folder = local.persistent_folder
fqdn = local.rustdesk_fqdn
public_key = var.rustdesk_public_key
private_key = var.rustdesk_private_key
}
module "m3uproxy" {
source = "../modules/m3uproxy"
persistent_folder = local.persistent_folder
tag = local.m3uproxy_version
fqdn = local.m3uproxy_fqdn
# Secret and password for M3UProxy
secret = var.m3uproxy_secret
admin_password = var.m3uproxy_admin_password
# GeoIP settings
maxmind_account_id = var.maxmind_account_id
maxmind_license_key = var.maxmind_license_key
geoip_cron_schedule = local.geoip_cron_schedule
geoip_editions = local.geoip_editions
# Wireguard settings (VPN)
wireguard_private_key = var.wireguard_private_key
wireguard_public_key = var.wireguard_public_key
}
-36
View File
@@ -1,36 +0,0 @@
module "websites" {
source = "../modules/websites"
persistent_folder = local.persistent_folder
primary_domain = local.primary_domain
websites = local.websites
}
moved {
from = kubernetes_namespace.website
to = module.websites.kubernetes_namespace.website
}
moved {
from = kubernetes_service_account.website_service_account
to = module.websites.kubernetes_service_account.website_service_account
}
moved {
from = kubernetes_service.website
to = module.websites.kubernetes_service.website
}
moved {
from = kubernetes_config_map.nginx_config
to = module.websites.kubernetes_config_map.nginx_config
}
moved {
from = kubernetes_ingress_v1.website_ingress
to = module.websites.kubernetes_ingress_v1.website_ingress
}
moved {
from = kubernetes_deployment.website
to = module.websites.kubernetes_deployment.website
}
+30
View File
@@ -0,0 +1,30 @@
locals {
persistent_folder = var.persistent_folder
m3uproxy_version = var.tag
m3uproxy_fqdn = var.fqdn
wireguard_version = "1.0.20210914-r4-ls54"
squid_version = "6.1-23.10_edge"
geoip_image = "maxmindinc/geoipupdate"
geoip_version = "latest"
geoip_cron_schedule = var.geoip_cron_schedule
geoip_editions = var.geoip_editions
m3uproxy_path = "${local.persistent_folder}/m3uproxy"
m3uproxy_cache_path = "${local.m3uproxy_path}/cache"
squid_app_path = "${local.m3uproxy_path}/squid"
geoip_path = "${local.m3uproxy_path}/geoip"
wireguard_address = "192.168.5.3/32"
wireguard_dns = "192.168.5.1"
wireguard_allowed_ips = [
"192.168.5.1/32",
"192.168.5.3/32",
"0.0.0.0/0"
]
wireguard_endpoint = "188.82.170.183"
wireguard_endpoint_port = 1195
m3uproxy_config = templatefile("${path.module}/resources/m3uproxy/m3uproxy.json", {
m3uproxy_secret = var.secret
})
}
@@ -1,23 +1,3 @@
locals {
m3uproxy_path = "${local.persistent_folder}/m3uproxy"
m3uproxy_cache_path = "${local.m3uproxy_path}/cache"
squid_app_path = "${local.m3uproxy_path}/squid"
geoip_path = "${local.m3uproxy_path}/geoip"
wireguard_address = "192.168.5.3/32"
wireguard_dns = "192.168.5.1"
wireguard_allowed_ips = [
"192.168.5.1/32",
"192.168.5.3/32",
"0.0.0.0/0"
]
wireguard_endpoint = "188.82.170.183"
wireguard_endpoint_port = 1195
m3uproxy_config = templatefile("${path.module}/resources/m3uproxy/m3uproxy.json", {
m3uproxy_secret = var.m3uproxy_secret
})
}
resource "kubernetes_namespace" "m3uproxy" { resource "kubernetes_namespace" "m3uproxy" {
metadata { metadata {
annotations = { annotations = {
@@ -37,7 +17,7 @@ resource "kubernetes_secret" "m3uproxy_admin_credentials" {
} }
data = { data = {
username = "tv_admin" username = "tv_admin"
password = var.m3uproxy_admin_password password = var.admin_password
} }
type = "Opaque" type = "Opaque"
} }
+9
View File
@@ -0,0 +1,9 @@
terraform {
required_version = "~>1.8"
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~>2.18"
}
}
}
+61
View File
@@ -0,0 +1,61 @@
variable "persistent_folder" {
description = "The path to the persistent folder"
type = string
}
variable "fqdn" {
description = "The fully qualified domain name for the Rustdesk server"
type = string
}
variable "tag" {
description = "The version of Rustdesk to install"
type = string
default = "latest"
}
variable "maxmind_account_id" {
description = "Maxmind account ID"
type = string
}
variable "maxmind_license_key" {
description = "Maxmind license key"
type = string
sensitive = true
}
variable "geoip_cron_schedule" {
description = "The cron schedule for the geoipupdate job"
type = string
default = "0 0 * * *"
}
variable "geoip_editions" {
description = "The editions of the GeoIP database to update"
type = list(string)
default = ["GeoLite2-Country", "GeoLite2-City"]
}
variable "admin_password" {
description = "The password for the M3UProxy admin user"
type = string
sensitive = true
}
variable "secret" {
description = "The secret for JWT signing in M3UProxy"
type = string
sensitive = true
}
variable "wireguard_public_key" {
description = "The public key for Wireguard"
type = string
}
variable "wireguard_private_key" {
description = "The private key for Wireguard"
type = string
sensitive = true
}
@@ -1,5 +1,6 @@
locals { locals {
persistent_folder = var.persistent_folder persistent_folder = var.persistent_folder
websites_path = "${local.persistent_folder}/web"
primary_domain = var.primary_domain primary_domain = var.primary_domain
websites = var.websites websites = var.websites
} }
@@ -1,7 +1,3 @@
locals {
websites_path = "${local.persistent_folder}/web"
}
resource "kubernetes_namespace" "website" { resource "kubernetes_namespace" "website" {
metadata { metadata {
annotations = { annotations = {
@@ -126,7 +122,7 @@ resource "kubernetes_deployment" "website" {
container { container {
name = "website" name = "website"
image = "nginx:stable-alpine" image = "nginx:${var.tag}"
image_pull_policy = "Always" image_pull_policy = "Always"
resources { resources {
@@ -8,6 +8,12 @@ variable "primary_domain" {
type = string type = string
} }
variable "tag" {
description = "The version of the websites to install"
type = string
default = "stable-alpine"
}
variable "websites" { variable "websites" {
description = "A list of websites to be deployed" description = "A list of websites to be deployed"
type = map(object({ type = map(object({
+8
View File
@@ -0,0 +1,8 @@
locals {
persistent_folder = var.persistent_folder
rustdesk_path = "${local.persistent_folder}/rustdesk"
rustdesk_version = var.tag
rustdesk_fqdn = var.fqdn
}
@@ -1,7 +1,3 @@
locals {
rustdesk_path = "${local.persistent_folder}/rustdesk"
}
resource "kubernetes_namespace" "rustdesk" { resource "kubernetes_namespace" "rustdesk" {
metadata { metadata {
name = "rustdesk" name = "rustdesk"
@@ -27,8 +23,8 @@ resource "kubernetes_secret" "rustdesk_keys" {
} }
data = { data = {
"id_ed25519" = var.rustdesk_private_key "id_ed25519" = var.private_key
"id_ed25519.pub" = var.rustdesk_public_key "id_ed25519.pub" = var.public_key
} }
} }
+9
View File
@@ -0,0 +1,9 @@
terraform {
required_version = "~>1.8"
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~>2.18"
}
}
}
+27
View File
@@ -0,0 +1,27 @@
variable "persistent_folder" {
description = "The path to the persistent folder"
type = string
}
variable "fqdn" {
description = "The fully qualified domain name for the Rustdesk server"
type = string
}
variable "tag" {
description = "The version of Rustdesk to install"
type = string
default = "latest"
}
variable "public_key" {
description = "Rustdesk public key"
type = string
sensitive = false
}
variable "private_key" {
description = "Rustdesk private key"
type = string
sensitive = true
}