GCP google_sql_user password not being set properly

32 Views Asked by At

I have the below Terraform file I am using to deploy to GPC using my Github Actions pipeline. I am using the google_sql_user terraform registry. I see that my database is being deployed, however; I cannot connect to the database using the ttuser postgres user. I am able to connect to the database using the postgres user, using the same password as the one used to create ttpass. When I connect to the database, I observe that the ttuser is there on the database, I just cannot connect to it. Looking for guidance, potentially there is something I am missing on the terraform?

variable "project_id" {
  type = string
  description = "GCP Account Project ID"
}

variable "db_password" {
  type = string
  description = "Password for DB user"
}

provider "google" {
  project     = var.project_id
  region      = "us-central1"
  zone        = "us-central1-c"
}

resource "google_sql_database_instance" "main" {
  name             = "training-tracker-dev"
  database_version = "POSTGRES_15"
  region           = "us-central1"

  root_password = var.db_password

  settings {
    tier = "db-f1-micro"
  }
}

resource "google_sql_user" "users" {
  name = "ttuser"
  instance = google_sql_database_instance.main.name
  password = var.db_password
  depends_on = [ google_sql_database_instance.main ]
}
0

There are 0 best solutions below