|
| 1 | +// Each cell of the dbsync extension containes 1 PVC, 1 Postgres instance, 1 |
| 2 | +// PGBouncer that acts proxy and an amount of instances (commonly 3, one per |
| 3 | +// network). |
| 4 | +locals { |
| 5 | + postgres_host = "postgres-dbsync-v3-${var.salt}" |
| 6 | + db_volume_claim = coalesce(var.db_volume_claim, "pvc-${var.salt}") |
| 7 | + postgres_config_name = coalesce(var.postgres_config_name, "postgres-config-${var.salt}") |
| 8 | +} |
| 9 | +module "dbsync_pvc" { |
| 10 | + source = "../pvc" |
| 11 | + namespace = var.namespace |
| 12 | + volume_name = var.volume_name |
| 13 | + storage_size = var.storage_size |
| 14 | + name = local.db_volume_claim |
| 15 | +} |
| 16 | + |
| 17 | +module "dbsync_postgres" { |
| 18 | + source = "../postgres" |
| 19 | + |
| 20 | + namespace = var.namespace |
| 21 | + db_volume_claim = local.db_volume_claim |
| 22 | + instance_name = local.postgres_host |
| 23 | + postgres_config_name = local.postgres_config_name |
| 24 | + topology_zone = var.topology_zone |
| 25 | + postgres_image_tag = var.postgres_image_tag |
| 26 | + postgres_secret_name = var.postgres_secret_name |
| 27 | + postgres_resources = var.postgres_resources |
| 28 | +} |
| 29 | + |
| 30 | +module "dbsync_pgbouncer" { |
| 31 | + source = "../pgbouncer" |
| 32 | + |
| 33 | + namespace = var.namespace |
| 34 | + pg_bouncer_replicas = var.pgbouncer_replicas |
| 35 | + certs_configmap_name = var.certs_configmap_name |
| 36 | + pg_bouncer_user_settings = var.pgbouncer_user_settings |
| 37 | + pg_bouncer_auth_user_password = var.pgbouncer_auth_user_password |
| 38 | + instance_role = "pgbouncer" |
| 39 | + postgres_secret_name = var.postgres_secret_name |
| 40 | + instance_name = "postgres-dbsync-v3-${var.salt}" |
| 41 | + postgres_instance_name = local.postgres_host |
| 42 | +} |
| 43 | + |
| 44 | +module "dbsync_instances" { |
| 45 | + source = "../instance" |
| 46 | + for_each = var.instances |
| 47 | + |
| 48 | + namespace = var.namespace |
| 49 | + network = each.value.network |
| 50 | + salt = coalesce(each.value.salt, var.salt) |
| 51 | + dbsync_image_tag = each.value.dbsync_image_tag |
| 52 | + node_n2n_tcp_endpoint = each.value.node_n2n_tcp_endpoint |
| 53 | + release = each.value.release |
| 54 | + topology_zone = coalesce(each.value.topology_zone, var.topology_zone) |
| 55 | + sync_status = each.value.sync_status |
| 56 | + |
| 57 | + enable_postgrest = each.value.enable_postgrest |
| 58 | + postgres_database = "dbsync-${each.value.network}" |
| 59 | + postgres_instance_name = local.postgres_host |
| 60 | + postgres_secret_name = var.postgres_secret_name |
| 61 | + |
| 62 | + dbsync_resources = coalesce(each.value.dbsync_resources, { |
| 63 | + "limits" = { |
| 64 | + "memory" = "4Gi" |
| 65 | + } |
| 66 | + "requests" = { |
| 67 | + "memory" = "4Gi" |
| 68 | + "cpu" = "100m" |
| 69 | + } |
| 70 | + }) |
| 71 | + dbsync_volume = coalesce(each.value.dbsync_volume, { |
| 72 | + manual = false |
| 73 | + storage_class = "fast" |
| 74 | + size = "10Gi" |
| 75 | + }) |
| 76 | +} |
0 commit comments