|
| 1 | +// Create kafka cluster with 3vcpu, 12MB memory and autorebalance |
| 2 | +resource "google_managed_kafka_cluster" "mimir_cluster" { |
| 3 | + project = module.project.project_id |
| 4 | + cluster_id = "mimir-cluster" |
| 5 | + location = "us-central1" |
| 6 | + capacity_config { |
| 7 | + vcpu_count = 3 |
| 8 | + memory_bytes = 12884901888 |
| 9 | + } |
| 10 | + gcp_config { |
| 11 | + access_config { |
| 12 | + network_configs { |
| 13 | + subnet = "projects/${module.project.project_id}/regions/us-central1/subnetworks/subnet-01" |
| 14 | + } |
| 15 | + } |
| 16 | + } |
| 17 | + rebalance_config { |
| 18 | + mode = "AUTO_REBALANCE_ON_SCALE_UP" |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +// Create mimir-ingest topic with 12 partition count |
| 23 | +resource "google_managed_kafka_topic" "mimir_ingest" { |
| 24 | + project = module.project.project_id |
| 25 | + topic_id = "mimir-ingest" |
| 26 | + cluster = google_managed_kafka_cluster.mimir_cluster.cluster_id |
| 27 | + location = "us-central1" |
| 28 | + partition_count = 12 # must be >= ingesters per zone |
| 29 | + replication_factor = 3 # Managed Kafka requires >= 3 |
| 30 | + |
| 31 | + // Set max byte to 16MB because mimir default is 15.2MB |
| 32 | + configs = { |
| 33 | + "max.message.bytes" = "16000000" |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +resource "google_service_account" "mimir_kafka" { |
| 39 | + project = module.project.project_id |
| 40 | + account_id = "mimir-kafka" |
| 41 | + display_name = "Mimir Kafka Client" |
| 42 | +} |
| 43 | + |
| 44 | +resource "google_service_account_key" "mimir_kafka" { |
| 45 | + service_account_id = google_service_account.mimir_kafka.id |
| 46 | +} |
| 47 | + |
| 48 | +resource "google_project_iam_member" "mimir_kafka" { |
| 49 | + project = module.project.project_id |
| 50 | + role = "roles/managedkafka.client" |
| 51 | + member = "serviceAccount:${google_service_account.mimir_kafka.email}" |
| 52 | +} |
| 53 | + |
| 54 | +resource "google_secret_manager_secret" "mimir_kafka_credentials" { |
| 55 | + project = module.project.project_id |
| 56 | + secret_id = "mimir-kafka-credentials" |
| 57 | + replication { |
| 58 | + auto {} |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +resource "google_secret_manager_secret_version" "mimir_kafka_credentials" { |
| 63 | + secret = google_secret_manager_secret.mimir_kafka_credentials.id |
| 64 | + secret_data = jsonencode({ |
| 65 | + username = google_service_account.mimir_kafka.email |
| 66 | + password = google_service_account_key.mimir_kafka.private_key |
| 67 | + }) |
| 68 | +} |
0 commit comments