change pipeline generation + add tf dockerfile

This commit is contained in:
Work 2026-01-26 15:58:04 +03:00
parent 06f4246c07
commit 2fb0b416d7
2 changed files with 20 additions and 28 deletions

View File

@ -1,23 +1,19 @@
# Включение корневой конфигурации
include "root" { include "root" {
path = find_in_parent_folders() path = find_in_parent_folders()
} }
# Включение конфигурации окружения
include "env" { include "env" {
path = find_in_parent_folders("env.hcl") path = find_in_parent_folders("env.hcl")
expose = true expose = true
merge_strategy = "deep" merge_strategy = "deep"
} }
# Зависимости от других компонентов
dependency "namespace" { dependency "namespace" {
config_path = "../namespace" config_path = "../namespace"
mock_outputs = { mock_outputs = {
name = "pulse" name = "pulse"
} }
mock_outputs_allowed_terraform_commands = ["validate", "plan"] mock_outputs_allowed_terraform_commands = ["validate", "plan"]
# При apply используем реальные outputs, не mock
} }
dependency "s3" { dependency "s3" {
@ -28,7 +24,6 @@ dependency "s3" {
secret_key = "mock-secret-key" secret_key = "mock-secret-key"
} }
mock_outputs_allowed_terraform_commands = ["validate", "plan"] mock_outputs_allowed_terraform_commands = ["validate", "plan"]
# При apply используем реальные outputs, не mock
} }
dependency "database" { dependency "database" {
@ -40,10 +35,8 @@ dependency "database" {
password = "mock-password" password = "mock-password"
} }
mock_outputs_allowed_terraform_commands = ["validate", "plan"] mock_outputs_allowed_terraform_commands = ["validate", "plan"]
# При apply используем реальные outputs, не mock
} }
# Сертификат Yandex Cloud PostgreSQL (константа, не копируется в infrastructure.yaml)
locals { locals {
yc_postgresql_ca_cert = <<-EOT yc_postgresql_ca_cert = <<-EOT
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
@ -112,20 +105,26 @@ EOT
env_name = basename(dirname(get_terragrunt_dir())) env_name = basename(dirname(get_terragrunt_dir()))
env_config = local.infra_config.environments[local.env_name] env_config = local.infra_config.environments[local.env_name]
secrets = local.env_config.secrets secrets = local.env_config.secrets
namespace_name = dependency.namespace.outputs.name
s3_bucket_name = dependency.s3.outputs.bucket_name
s3_access_key = dependency.s3.outputs.access_key
s3_secret_key = dependency.s3.outputs.secret_key
db_host = dependency.database.outputs.host
db_database_name = dependency.database.outputs.database_name
db_user_name = dependency.database.outputs.user_name
db_password = dependency.database.outputs.password
} }
# Путь к модулю
terraform { terraform {
source = "${get_terragrunt_dir()}/../../../modules//k8s-secret" source = "${get_terragrunt_dir()}/../../../modules//k8s-secret"
} }
# Входные переменные из конфига - модуль сам формирует data из зависимостей
inputs = { inputs = {
# Передаем секреты как есть из infrastructure.yaml, модуль сам обработает type и dependencies
secrets = [ secrets = [
for secret in local.secrets : { for secret in local.secrets : {
name = secret.name name = secret.name
namespace = dependency.namespace.outputs.name namespace = local.namespace_name
secret_type = secret.type secret_type = secret.type
registry_url = try(secret.registry_url, "") registry_url = try(secret.registry_url, "")
dependencies = try(secret.dependencies, {}) dependencies = try(secret.dependencies, {})
@ -137,39 +136,32 @@ inputs = {
} }
] ]
# Зависимости от других модулей
s3_outputs = { s3_outputs = {
bucket_name = dependency.s3.outputs.bucket_name bucket_name = local.s3_bucket_name
access_key = dependency.s3.outputs.access_key access_key = local.s3_access_key
secret_key = dependency.s3.outputs.secret_key secret_key = local.s3_secret_key
} }
# Database outputs как map, ключ = "cluster_id:database_name:user_name"
# Собираем все базы данных из infrastructure.yaml
database_outputs_map = { database_outputs_map = {
# Текущая база из dependency
"${local.env_config.databases[0].cluster_id}:${local.env_config.databases[0].database.name}:${local.env_config.databases[0].user.name}" = { "${local.env_config.databases[0].cluster_id}:${local.env_config.databases[0].database.name}:${local.env_config.databases[0].user.name}" = {
host = dependency.database.outputs.host host = local.db_host
database_name = dependency.database.outputs.database_name database_name = local.db_database_name
user_name = dependency.database.outputs.user_name user_name = local.db_user_name
password = dependency.database.outputs.password password = local.db_password
} }
} }
# Константы
constants = { constants = {
s3_endpoint = "https://storage.yandexcloud.net" s3_endpoint = "https://storage.yandexcloud.net"
postgres_port = "6432" postgres_port = "6432"
postgres_ca = local.yc_postgresql_ca_cert postgres_ca = local.yc_postgresql_ca_cert
} }
# Environment variables
env_vars = { env_vars = {
DOCKER_REGISTRY_USERNAME = get_env("DOCKER_REGISTRY_USERNAME", "") DOCKER_REGISTRY_USERNAME = get_env("DOCKER_REGISTRY_USERNAME", "")
DOCKER_REGISTRY_PASSWORD = get_env("DOCKER_REGISTRY_PASSWORD", "") DOCKER_REGISTRY_PASSWORD = get_env("DOCKER_REGISTRY_PASSWORD", "")
} }
# Провайдеры (передаются в сгенерированный provider.tf)
yc_token = get_env("YC_TOKEN", "") yc_token = get_env("YC_TOKEN", "")
yc_cloud_id = get_env("YC_CLOUD_ID", "") yc_cloud_id = get_env("YC_CLOUD_ID", "")
yc_folder_id = get_env("YC_STAGE_FOLDER_ID", get_env("YC_FOLDER_ID", "")) yc_folder_id = get_env("YC_STAGE_FOLDER_ID", get_env("YC_FOLDER_ID", ""))

View File

@ -94,7 +94,7 @@ validate-${job_prefix}:
- export TF_PLUGIN_CACHE_DIR=/root/.terraform.d/plugin-cache - export TF_PLUGIN_CACHE_DIR=/root/.terraform.d/plugin-cache
script: script:
- env | grep -E "(S3_|AWS_)" || echo "No S3/AWS vars found" - env | grep -E "(S3_|AWS_)" || echo "No S3/AWS vars found"
- terragrunt init -reconfigure - terragrunt init -upgrade -reconfigure
- terragrunt validate - terragrunt validate
rules: rules:
- if: '\$CI_PIPELINE_SOURCE == "merge_request_event"' - if: '\$CI_PIPELINE_SOURCE == "merge_request_event"'
@ -128,7 +128,7 @@ plan-${job_prefix}:
- ls -la - ls -la
- rm -rf .terragrunt-cache - rm -rf .terragrunt-cache
script: script:
- terragrunt init -reconfigure - terragrunt init -upgrade -reconfigure
- terragrunt plan -out=tfplan - terragrunt plan -out=tfplan
rules: rules:
- if: '\$CI_COMMIT_BRANCH == "master" || \$CI_COMMIT_BRANCH == "main"' - if: '\$CI_COMMIT_BRANCH == "master" || \$CI_COMMIT_BRANCH == "main"'
@ -174,7 +174,7 @@ apply-${job_prefix}:
- ls -la - ls -la
- rm -rf .terragrunt-cache - rm -rf .terragrunt-cache
script: script:
- terragrunt init -reconfigure || true - terragrunt init -upgrade -reconfigure
- terragrunt apply tfplan - terragrunt apply tfplan
rules: rules:
- if: '\$CI_COMMIT_BRANCH == "master" || \$CI_COMMIT_BRANCH == "main"' - if: '\$CI_COMMIT_BRANCH == "master" || \$CI_COMMIT_BRANCH == "main"'