# ============================================================================= # Flask Consumer — читает Kafka, пишет в ClickHouse # ============================================================================= locals { consumer_kafka_secrets = try(jsondecode(nubes_kafka.main.vault_secrets["users"]), jsondecode(nubes_kafka.main.vault_secrets["secrets"]), tomap({})) consumer_ch_secrets = try(jsondecode(nubes_clickhouse.main.vault_secrets["users"]), jsondecode(nubes_clickhouse.main.vault_secrets["secrets"]), tomap({})) consumer_kafka_brokers = try(nubes_kafka.main.state_out_flat["bootstrapServers"], "") consumer_kafka_password = try(nonsensitive(lookup(local.consumer_kafka_secrets, "iot-app", tomap({})).password), "") consumer_ch_host = try(nubes_clickhouse.main.state_out_flat["internalMaster"], "") consumer_ch_password = try(nonsensitive(lookup(local.consumer_ch_secrets, "iot_writer", tomap({})).password), "") } resource "nubes_flask" "consumer" { resource_name = local.consumer_resource_name startup_configuration = { resource_realm = var.realm } cluster_configuration = { cpu = local.consumer_cpu memory = local.consumer_memory replicas = local.consumer_replicas } access_configuration = { domain = local.consumer_domain } app_configuration = { version = "3.12" git_path = local.consumer_git_path health_path = "/health" } git_revision = local.consumer_git_revision operation_timeout = local.consumer_timeout json_env = jsonencode({ KAFKA_BROKERS = local.consumer_kafka_brokers KAFKA_TOPIC = local.kafka_topic_name KAFKA_USERNAME = local.kafka_username KAFKA_PASSWORD = local.consumer_kafka_password KAFKA_GROUP_ID = "iot-consumer-group" CH_HOST = local.consumer_ch_host CH_PORT = local.ch_http_port CH_USER = local.ch_username CH_PASSWORD = local.consumer_ch_password CH_DATABASE = local.ch_db_name }) depends_on = [nubes_kafka.main, nubes_clickhouse.main] }