{"id":20986901,"url":"https://github.com/christippett/terraform-google-cloud-sql-pgbouncer","last_synced_at":"2025-05-14T17:33:32.562Z","repository":{"id":52609175,"uuid":"272275274","full_name":"christippett/terraform-google-cloud-sql-pgbouncer","owner":"christippett","description":"Automatically configure and deploy PgBouncer on Google Cloud with this Terraform module","archived":false,"fork":false,"pushed_at":"2023-02-17T08:51:49.000Z","size":34,"stargazers_count":27,"open_issues_count":5,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-02-27T21:01:13.106Z","etag":null,"topics":["cloud-sql","google-cloud","hacktoberfest","pgbouncer","postgresql","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/christippett.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-14T20:08:07.000Z","updated_at":"2023-02-20T14:59:38.000Z","dependencies_parsed_at":"2023-02-10T22:01:31.428Z","dependency_job_id":null,"html_url":"https://github.com/christippett/terraform-google-cloud-sql-pgbouncer","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christippett%2Fterraform-google-cloud-sql-pgbouncer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christippett%2Fterraform-google-cloud-sql-pgbouncer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christippett%2Fterraform-google-cloud-sql-pgbouncer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christippett%2Fterraform-google-cloud-sql-pgbouncer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christippett","download_url":"https://codeload.github.com/christippett/terraform-google-cloud-sql-pgbouncer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225303981,"owners_count":17453037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-sql","google-cloud","hacktoberfest","pgbouncer","postgresql","terraform"],"created_at":"2024-11-19T06:15:19.981Z","updated_at":"2024-11-19T06:15:20.585Z","avatar_url":"https://github.com/christippett.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform PgBouncer for Cloud SQL\n\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/christippett/terraform-google-cloud-sql-pgbouncer?label=Version)](./CHANGELOG.md) [![Terraform Registry](https://img.shields.io/badge/Terraform-Registry-623CE4)](https://registry.terraform.io/modules/christippett/cloud-sql-pgbouncer/)\n\nLet Cloud Run wild on your database 🐆\n\n## Overview\n\nThis module creates a Compute Engine instance running PgBouncer that sits in front of a Cloud SQL or self-hosted PostgreSQL instance.\n\nRefer to the [examples/](./examples/) sub-directory for a complete example of how this module can be integrated and used with Cloud SQL.\n\n```hcl\nmodule \"pgbouncer\" {\n  source  = \"christippett/cloud-sql-pgbouncer/google\"\n  version = \"~\u003e1.2\"\n\n  project      = var.project\n  name         = \"pgbouncer\"\n  zone         = \"us-central1-a\"\n  subnetwork   = \"subnet-1\"\n  machine_type = \"f1-micro\"\n\n  port          = 25128\n  database_host = 5432\n\n  users = [\n    { name = \"admin\", password = \"password\", admin = true },\n    { name = \"user\", password = \"md55f4dcc3b5aa765d61d8327deb882cf99\" }\n  ]\n}\n```\n\n## Authentication\n\nThe module accepts both plain-text or pre-hashed md5 passwords as input. Plain-text passwords will be automatically hashed to md5 and their hashed values stored in Terraform's state.\n\nThe `users` map accepts an optional `admin` key. When this is set to `true`, the user will be added to the list of PgBouncer admins and stats users.\n\n## Configuring PgBouncer\n\nOnly a subset of PgBouncer's configuration are exposed as input variables. If you wish to customise PgBouncer further, you're able to provide your own configuration via the `pgbouncer_custom_config` input variable (type `map(string)`). The values from this variable will be added to `pgbouncer.ini`.\n\nThe `pgbouncer.ini` template used by this module can be found [here](./modules/pgbouncer_cloud_init/templates/pgbouncer.ini.tmpl). Refer to the [official PgBouncer documentation](https://www.pgbouncer.org/config.html) for a full list of configuration options.\n\n## Inputs\n\n| Name                    | Description                                                                                                                                                                                 | Type     | Default                  | Required |\n| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------ | :------: |\n| database_host           | The host address of the Cloud SQL instance to connect to.                                                                                                                                   | `string` | n/a                      |   yes    |\n| name                    | The name of the PgBouncer instance.                                                                                                                                                         | `string` | n/a                      |   yes    |\n| port                    | The port used by PgBouncer to listen on.                                                                                                                                                    | `number` | n/a                      |   yes    |\n| project                 | The ID of the project where PgBouncer will be created.                                                                                                                                      | `string` | n/a                      |   yes    |\n| users                   | The list of users to be created in PgBouncer's userlist.txt. Passwords can be provided as plain-text or md5 hashes.                                                                         | `list`   | n/a                      |   yes    |\n| zone                    | The zone where PgBouncer will be created.                                                                                                                                                   | `string` | n/a                      |   yes    |\n| auth_query              | Query to load user’s password from database.                                                                                                                                                | `string` | `null`                   |    no    |\n| auth_user               | Any user not specified in `users` will be queried through the `auth_query` query from `pg_shadow` in the database, using `auth_user`. The user for `auth_user` must be included in `users`. | `string` | `null`                   |    no    |\n| boot_image              | The boot image used by PgBouncer instances. Defaults to the latest LTS Container Optimized OS version. Must be an image compatible with cloud-init (https://cloud-init.io).                 | `string` | `\"cos-cloud/cos-89-lts\"` |    no    |\n| default_pool_size       | Maximum number of server connections to allow per user/database pair.                                                                                                                       | `number` | `20`                     |    no    |\n| disable_public_ip       | Flag to disable the PgBouncer instance from being assigned an external, public IP                                                                                                           | `bool`   | `false`                  |    no    |\n| disable_service_account | Flag to disable attaching a service account to the PgBouncer instance.                                                                                                                      | `bool`   | `false`                  |    no    |\n| machine_type            | The machine type of PgBouncer instances.                                                                                                                                                    | `string` | `\"f1-micro\"`             |    no    |\n| max_client_connections  | Maximum number of client connections allowed.                                                                                                                                               | `number` | `100`                    |    no    |\n| max_db_connections      | The maximum number of server connections per database (regardless of user). 0 is unlimited.                                                                                                 | `number` | `0`                      |    no    |\n| module_depends_on       | List of modules or resources this module depends on.                                                                                                                                        | `list`   | `[]`                     |    no    |\n| pgbouncer_custom_config | Custom PgBouncer configuration values to be appended to `pgbouncer.ini`.                                                                                                                    | `string` | `\"\"`                     |    no    |\n| pgbouncer_image_tag     | The tag to use for the base PgBouncer `edoburu/pgbouncer` Docker image used by this module.                                                                                                 | `string` | `\"latest\"`               |    no    |\n| pool_mode               | Specifies when a server connection can be reused by other clients. Possible values are `session`, `transaction` or `statement`.                                                             | `string` | `\"transaction\"`          |    no    |\n| public_ip_address       | The public IP address to assign to the PgBouncer instance. If not given, one will be generated. Note: setting this value will limit the instance count to 1.                                | `string` | `null`                   |    no    |\n| service_account_email   | The service account e-mail address. If not given, the default Google Compute Engine service account is used.                                                                                | `any`    | `null`                   |    no    |\n| service_account_scopes  | A list of service scopes to apply to the PgBouncer instance. Default is the full `cloud-platform` access scope.                                                                             | `any`    | `null`                   |    no    |\n| subnetwork              | The name or self-link of the subnet where PgBouncer will be created. Either network or subnetwork must be provided.                                                                         | `string` | `null`                   |    no    |\n| tags                    | A list of tags to assign to PgBouncer instances.                                                                                                                                            | `list`   | `[]`                     |    no    |\n\n## Outputs\n\n| Name               | Description                                                        |\n| ------------------ | ------------------------------------------------------------------ |\n| instance_name      | The name for the PgBouncer instance.                               |\n| port               | The port number PgBouncer listens on.                              |\n| private_ip_address | The first private IPv4 address assigned to the PgBouncer instance. |\n| public_ip_address  | The first public IPv4 address assigned for the PgBouncer instance. |\n\n## Requirements\n\nThese sections describe requirements for using this module.\n\n### Software\n\nThe following dependencies must be available:\n\n- [Terraform][terraform] v0.13\n- [Terraform Provider for GCP][terraform-provider-gcp] plugin v3.5\n\n### Service Account\n\nA service account with the following roles must be used to provision\nthe resources of this module:\n\n- `roles/compute.instanceAdmin`\n- `roles/iam.serviceAccountUser`\n\n### APIs\n\nA project with the following APIs enabled must be used to host the\nresources of this module:\n\n- `compute.googleapis.com`\n\n[terraform-provider-gcp]: https://www.terraform.io/docs/providers/google/index.html\n[terraform]: https://www.terraform.io/downloads.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristippett%2Fterraform-google-cloud-sql-pgbouncer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristippett%2Fterraform-google-cloud-sql-pgbouncer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristippett%2Fterraform-google-cloud-sql-pgbouncer/lists"}