Skip to content

Commit

Permalink
feat: Automate connection profile
Browse files Browse the repository at this point in the history
  • Loading branch information
k3yss committed Jul 29, 2024
1 parent 2b55596 commit fa970c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/postgresql/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ resource "postgresql_extension" "pglogical" {
database = "postgres"
}

resource "google_database_migration_service_connection_profile" "connection_profile" {
count = local.upgradable ? 1 : 0
location = local.region
connection_profile_id = "${google_sql_database_instance.instance.name}-id"
display_name = "${google_sql_database_instance.instance.name}-connection-profile"

postgresql {
cloud_sql_id = google_sql_database_instance.instance.name
host = google_sql_database_instance.instance.private_ip_address
port = local.database_port

username = google_sql_user.admin.name
password = google_sql_user.admin.password
}
depends_on = [google_sql_database_instance.instance]
}

resource "google_sql_database_instance" "instance" {
name = "${local.instance_name}-${random_id.db_name_suffix.hex}"

Expand Down Expand Up @@ -119,6 +136,7 @@ module "database" {

provider "postgresql" {
host = google_sql_database_instance.instance.private_ip_address
port = local.database_port
username = google_sql_user.admin.name
password = random_password.admin.result

Expand Down
7 changes: 7 additions & 0 deletions modules/postgresql/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ variable "upgradable" {
default = false
}

variable "database_port" {
description = "Instance is upgradable via Database Migration Service"
type = number
default = 5432
}

locals {
gcp_project = var.gcp_project
vpc_name = var.vpc_name
Expand All @@ -67,4 +73,5 @@ locals {
provision_read_replica = var.provision_read_replica
big_query_connection_location = var.big_query_connection_location
upgradable = var.upgradable
database_port = var.database_port
}

0 comments on commit fa970c9

Please sign in to comment.