diff --git a/DEV_STAND/CRUD/flask.tf b/DEV_STAND/CRUD/flask.tf new file mode 100644 index 0000000..70f1b5f --- /dev/null +++ b/DEV_STAND/CRUD/flask.tf @@ -0,0 +1,48 @@ +# ============================================================================= +# Flask — CRUD (та же PG, та же таблица что у Lucee) +# ============================================================================= +locals { + # Повторно используем pg_host/pg_user/pg_pass/pg_db из lucee.tf locals + flask_pg_host = nubes_postgres.main_pg.state_out_flat["internalMaster"] + flask_pg_user = nubes_postgres_user.crud_user_0.username + flask_pg_pass = nonsensitive(jsondecode(nubes_postgres.main_pg.vault_secrets["users"]).user4crudpg.password) + flask_pg_db = nubes_postgres_database.pg_db.db_name +} + +resource "nubes_flask" "appflask" { + resource_name = local.flask_resource_name + + startup_configuration = { + resource_realm = var.realm + } + + cluster_configuration = { + cpu = local.flask_cpu + memory = local.flask_memory + replicas = local.flask_replicas + } + + access_configuration = { + domain = local.flask_domain + } + + app_configuration = { + version = "3.12" + git_path = local.flask_git_path + health_path = "/" + } + + git_revision = local.flask_git_revision + + json_env = jsonencode({ + TABLE_NAME = local.crud_table_name + PGHOST = local.flask_pg_host + PGPORT = local.pg_port + PGUSER = local.flask_pg_user + PGPASSWORD = local.flask_pg_pass + PGDATABASE = local.flask_pg_db + PGSSLMODE = local.pg_ssl_mode + }) + + depends_on = [nubes_postgres.main_pg] +} diff --git a/DEV_STAND/CRUD/locals.tf b/DEV_STAND/CRUD/locals.tf new file mode 100644 index 0000000..96a07b7 --- /dev/null +++ b/DEV_STAND/CRUD/locals.tf @@ -0,0 +1,54 @@ +# ============================================================================= +# locals.tf — все настраиваемые значения модуля CRUD (PG + Lucee + Flask) +# Никакого хардкода в ресурсах — всё здесь. +# ============================================================================= + +locals { + # ─── PostgreSQL ────────────────────────────────────────────────────────── + pg_resource_name = "pg4crud" + pg_cpu = 500 + pg_memory = 512 + pg_replicas = 1 + pg_disk = 10 + pg_version = "17" + pg_retain = 14 + pg_schedule = "0 0 * * *" + pg_timeout = "11m" + + # ─── PostgreSQL User ───────────────────────────────────────────────────── + pg_username = "user4crudpg" + pg_role = "ddl_user" + pg_db_name = "db4crudpg" + + # ─── Lucee ─────────────────────────────────────────────────────────────── + lucee_git_revision = "94d6677" + lucee_resource_name = "luceecrud" + lucee_domain = "tflucee" + lucee_version = "5.4" + lucee_git_path = "https://gitea.services.ngcloud.ru/Nail/tfluceecrud.git" + lucee_cpu = 300 + lucee_memory = 512 + lucee_replicas = 1 + + # ─── Таблица CRUD ──────────────────────────────────────────────────────── + crud_table_name = "crud_items" + + # ─── Flask ─────────────────────────────────────────────────────────────── + flask_git_revision = "34c030c" + flask_resource_name = "flaskcrud" + flask_domain = "tfflask" + flask_git_path = "https://gitea.services.ngcloud.ru/Nail/tfflaskcrud.git" + flask_cpu = 300 + flask_memory = 512 + flask_replicas = 1 + + # ─── JDBC / БД ─────────────────────────────────────────────────────────── + jdbc_class = "org.postgresql.Driver" + jdbc_bundle_name = "org.postgresql.jdbc" + jdbc_bundle_version = "42.6.0" + jdbc_conn_limit = "5" + jdbc_live_timeout = "15" + jdbc_validate = "false" + pg_port = "5432" + pg_ssl_mode = "require" +} diff --git a/DEV_STAND/CRUD/lucee.tf b/DEV_STAND/CRUD/lucee.tf new file mode 100644 index 0000000..85d2e25 --- /dev/null +++ b/DEV_STAND/CRUD/lucee.tf @@ -0,0 +1,59 @@ +locals { + pg_host = nubes_postgres.main_pg.state_out_flat["internalMaster"] + pg_user = nubes_postgres_user.crud_user_0.username + pg_pass = nonsensitive(jsondecode(nubes_postgres.main_pg.vault_secrets["users"]).user4crudpg.password) + pg_db = nubes_postgres_database.pg_db.db_name +} + +resource "nubes_lucee" "applucee" { + resource_name = local.lucee_resource_name + + startup_configuration = { + resource_realm = var.realm + } + + cluster_configuration = { + cpu = local.lucee_cpu + memory = local.lucee_memory + replicas = local.lucee_replicas + } + + access_configuration = { + domain = local.lucee_domain + } + + app_configuration = { + version = local.lucee_version + git_path = local.lucee_git_path + } + + git_revision = local.lucee_git_revision + + json_env = jsonencode({ + TABLE_NAME = local.crud_table_name + testds_class = local.jdbc_class + testds_bundleName = local.jdbc_bundle_name + testds_bundleVersion = local.jdbc_bundle_version + testds_connectionString = "jdbc:postgresql://${local.pg_host}:5432/${local.pg_db}" + testds_username = local.pg_user + testds_password = local.pg_pass + testds_connectionLimit = local.jdbc_conn_limit + testds_liveTimeout = local.jdbc_live_timeout + testds_validate = local.jdbc_validate + + PGHOST = local.pg_host + PGPORT = local.pg_port + PGUSER = local.pg_user + PGPASSWORD = local.pg_pass + PGSSLMODE = local.pg_ssl_mode + DATABASE_URL = format( + "postgresql://%s:%s@%s:5432/%s", + local.pg_user, + local.pg_pass, + local.pg_host, + local.pg_db + ) + }) + + depends_on = [nubes_postgres.main_pg] +} diff --git a/DEV_STAND/CRUD/main.tf b/DEV_STAND/CRUD/main.tf new file mode 100644 index 0000000..00719d2 --- /dev/null +++ b/DEV_STAND/CRUD/main.tf @@ -0,0 +1,39 @@ +terraform { + required_providers { + nubes = { + source = "registry.kube5s.ru/nubes-dev/nubes" + version = "3.1.13" + } + } +} + +variable "api_token" { + type = string + sensitive = true + description = "Nubes API token" +} +# variable "s3_uid" { +# type = string +# sensitive = true +# description = "Nubes S3 UID" +# } +variable "realm" { + type = string + sensitive = true + description = "resource_realm parameter for nubes_postgres resource" +} +variable "s3_user_uid" { + type = string + description = "S3 user UUID" +} +variable "s3_name" { + type = string + description = "S3 user name" +} + +provider "nubes" { + api_token = var.api_token + api_endpoint = "https://lk-api-gateway-dev.ngcloud.ru/api/v1/svc" + # log_level = "debug" # none | info | debug, default = "none" +} + diff --git a/DEV_STAND/CRUD/postgres.tf b/DEV_STAND/CRUD/postgres.tf new file mode 100644 index 0000000..60dddb0 --- /dev/null +++ b/DEV_STAND/CRUD/postgres.tf @@ -0,0 +1,49 @@ +resource "nubes_postgres" "main_pg" { + resource_name = local.pg_resource_name + + startup_configuration = { + resource_realm = var.realm + } + + cluster_configuration = { + cpu = local.pg_cpu + memory = local.pg_memory + replicas = local.pg_replicas + disk = local.pg_disk + } + + access_configuration = { + master_ip_space = "no-needed" + master_access_list = jsonencode(["10.0.0.0/8"]) + slave_ip_space = "no-needed" + slave_access_list = jsonencode([]) + } + + postgres_configuration = { + version = local.pg_version + ssl_required = true + pooler_master = false + pooler_slave = false + } + + postgres_conf = jsonencode([{ + param_name = "log_connections" + param_value = "" + }]) + + backup_configuration = { + s3_uid = var.s3_name + retain = local.pg_retain + schedule = local.pg_schedule + } + + autoscale_configuration = { + enabled = false + schedule = 0 + percent = 10 + quota = 100 + } + + operation_timeout = local.pg_timeout + adopt_existing_on_create = true +} diff --git a/DEV_STAND/CRUD/postgres_user_db.tf b/DEV_STAND/CRUD/postgres_user_db.tf new file mode 100644 index 0000000..cb6c72b --- /dev/null +++ b/DEV_STAND/CRUD/postgres_user_db.tf @@ -0,0 +1,16 @@ +# ============================================================================= +# PostgreSQL — пользователи и базы данных +# ============================================================================= +resource "nubes_postgres_user" "crud_user_0" { + postgres_id = nubes_postgres.main_pg.id + username = local.pg_username + role = local.pg_role + adopt_existing_on_create = true +} + +resource "nubes_postgres_database" "pg_db" { + postgres_id = nubes_postgres.main_pg.id + db_name = local.pg_db_name + db_owner = nubes_postgres_user.crud_user_0.username + adopt_existing_on_create = true +} diff --git a/DEV_STAND/CRUD/terraform.tfvars.example b/DEV_STAND/CRUD/terraform.tfvars.example new file mode 100644 index 0000000..a9239ee --- /dev/null +++ b/DEV_STAND/CRUD/terraform.tfvars.example @@ -0,0 +1,20 @@ +# ============================================================================= +# terraform.tfvars.example — скопировать в terraform.tfvars и заполнить +# ============================================================================= + +# API-токен Nubes (из ЛК: Профиль → Токены) +api_token = "" + +# S3 UID — идентификатор S3-сервиса (UUID, см. ЛК → S3) +s3_uid = "" + +# resource_realm — кластер Kubernetes для развёртывания +# Возможные значения: iot-naeel, k8s-3-sandbox-nubes-ru, k8s-4-sandbox-nubes-ru, naeel-test-3 +realm = "" + +# S3-пользователь: UUID (s3_user_uid) ИЛИ имя (s3_name) +# Можно указать любое одно — провайдер сам найдёт другое по API +# UUID S3-пользователя (из ЛК → S3 → Пользователи) +s3_user_uid = "" +# Имя S3-пользователя (например, "my-s3-user") +s3_name = ""