TEST_STAND/PG: clean structure with README, variables.tf, .gitignore, terraform.tfvars.example

This commit is contained in:
“Naeel”
2026-07-03 10:49:28 +04:00
parent 9081309e13
commit c34c852096
6 changed files with 175 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
# Secrets
terraform.tfvars
# Terraform state and cache
.terraform/
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
+59
View File
@@ -0,0 +1,59 @@
# PostgreSQL `pg` — TEST стенд
Terraform-манифест для создания PostgreSQL + пользователь + база данных через провайдер `nubes-test/nubes`.
## Быстрый старт
```bash
# 1. Скопируй шаблон переменных
cp terraform.tfvars.example terraform.tfvars
# 2. Подставь свои значения в terraform.tfvars:
# api_token — Nubes API токен (TEST)
# s3_uid — UUID существующего S3 Object Storage (для бэкапов)
# realm — платформа/K8s-кластер (например k8s-3-sandbox-nubes-ru)
# 3. В resources.tf замени:
# - resource_name = "pg4tf033777" → своё имя
# - имена ресурсов "npg", "pg_user", "db2_app" → свои
# 4. Инициализация
terraform init
# 5. Проверка
terraform plan
# 6. Создать
terraform apply
# 7. Приостановить (suspend, не удаление)
terraform destroy
```
## Переменные
| Переменная | Описание | Где взять |
|---|---|---|
| `api_token` | API-токен Nubes (TEST) | Личный кабинет → Профиль → Токены |
| `s3_uid` | UUID S3 Object Storage | `terraform state list` существующего S3 |
| `realm` | Платформа развёртывания | `k8s-3-sandbox-nubes-ru` / `iot-naeel` / `naeel-test-3` |
## Провайдер
- **Источник**: `terra.k8c.ru/nubes-test/nubes`
- **Версия**: `5.0.57`
- **API**: `https://lk-api-gateway-test.ngcloud.ru/api/v1/svc`
## Структура параметров
Параметры PostgreSQL сгруппированы в JSON-блоки (map-fixed):
| Блок | Поля |
|---|---|
| `startup_configuration` | `resourceRealm` |
| `cluster_configuration` | `cpu`, `memory`, `replicas`, `disk` |
| `access_configuration` | `masterIpSpace`, `masterAccessList`, `slaveIpSpace`, `slaveAccessList` |
| `postgres_configuration` | `version`, `sslRequired`, `poolerMaster`, `poolerSlave` |
| `postgres_conf` | `[{paramName, paramValue}]` (массив) |
| `backup_configuration` | `s3Uid`, `retain`, `schedule` |
| `autoscale_configuration` | `enabled`, `schedule`, `percent`, `quota` |
+14
View File
@@ -0,0 +1,14 @@
terraform {
required_providers {
nubes = {
source = "terra.k8c.ru/nubes-test/nubes"
version = "5.0.57"
}
}
}
provider "nubes" {
api_token = var.api_token
api_endpoint = "https://lk-api-gateway-test.ngcloud.ru/api/v1/svc"
}
+66
View File
@@ -0,0 +1,66 @@
resource "nubes_postgres" "npg" {
resource_name = "pg4tf033777"
startup_configuration = jsonencode({
resourceRealm = var.realm
})
cluster_configuration = jsonencode({
cpu = "500"
memory = "512"
replicas = "1"
disk = "10"
})
access_configuration = jsonencode({
masterIpSpace = "no-needed"
masterAccessList = []
slaveIpSpace = "no-needed"
slaveAccessList = []
})
postgres_configuration = jsonencode({
version = "17"
sslRequired = true
poolerMaster = false
poolerSlave = false
})
postgres_conf = jsonencode([
{
paramName = "log_connections"
paramValue = "''"
}
])
backup_configuration = jsonencode({
s3Uid = var.s3_uid
retain = "7"
schedule = "0 0 * * *"
})
autoscale_configuration = jsonencode({
enabled = false
schedule = "0"
percent = "10"
quota = "100"
})
operation_timeout = "11m"
adopt_existing_on_create = true
}
resource "nubes_postgres_user" "pg_user" {
postgres_id = nubes_postgres.npg.id
username = "user0"
role = "ddl_user"
adopt_existing_on_create = true
}
resource "nubes_postgres_database" "db2_app" {
postgres_id = nubes_postgres.npg.id
db_name = "dbterra"
db_owner = nubes_postgres_user.pg_user.username
adopt_existing_on_create = true
}
+13
View File
@@ -0,0 +1,13 @@
# ───────────────────────────────────────────────────────────
# Terraform variables — TEST stand (nubes-test)
# Скопируй в terraform.tfvars и подставь реальные значения
# ───────────────────────────────────────────────────────────
# Nubes API токен для TEST
api_token = "вставь_свой_токен"
# UUID существующего экземпляра S3 Object Storage (для бэкапов)
s3_uid = "вставь_s3_user_uid"
# Платформа/K8s-кластер для развёртывания
realm = "k8s-3-sandbox-nubes-ru"
+15
View File
@@ -0,0 +1,15 @@
variable "api_token" {
description = "Nubes API token for TEST stand"
type = string
sensitive = true
}
variable "s3_uid" {
description = "UUID существующего экземпляра S3 Object Storage (для бэкапов)"
type = string
}
variable "realm" {
description = "Платформа/K8s-кластер для развёртывания PostgreSQL"
type = string
}