terraform-contour-mirror/modules/yc-database/main.tf
kochetkov.s be34bc617b refactor: Use unified infrastructure.yaml config file
- Add infrastructure.yaml as single source of truth (like values.yaml in Helm)
- Make all modules universal (no hardcoded entity names)
- Use existing PostgreSQL cluster instead of creating new one
- Add yc-database module for working with existing PostgreSQL
- Add k8s-secret module with lifecycle.ignore_changes support
- Update terragrunt.hcl files to read from infrastructure.yaml
- Remove scripts, use native Terragrunt functions (yamldecode)
2026-01-19 15:28:39 +03:00

47 lines
1.3 KiB
HCL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Модуль для работы с существующим PostgreSQL кластером
# Создает базу данных и пользователя в существующем кластере
# Генерация пароля для пользователя
resource "random_password" "user_password" {
length = var.password_length
special = var.password_special
upper = true
lower = true
numeric = true
}
# Получение информации о существующем кластере
data "yandex_mdb_postgresql_cluster" "existing" {
cluster_id = var.cluster_id
}
# Создание базы данных
resource "yandex_mdb_postgresql_database" "this" {
cluster_id = var.cluster_id
name = var.database_name
owner = yandex_mdb_postgresql_user.this.name
lc_collate = var.lc_collate
lc_type = var.lc_type
dynamic "extension" {
for_each = var.extensions
content {
name = extension.value
}
}
}
# Создание пользователя
resource "yandex_mdb_postgresql_user" "this" {
cluster_id = var.cluster_id
name = var.user_name
password = random_password.user_password.result
dynamic "permission" {
for_each = var.permissions
content {
database_name = permission.value.database_name
}
}
}