terraform-google-sql-db icon indicating copy to clipboard operation
terraform-google-sql-db copied to clipboard

Postgres Module: additional_users requires password

Open Ulminator opened this issue 4 years ago • 3 comments
trafficstars

When trying to create users with the additional_users variable it looks like the desired functionality is for the user's passwords to be defaulted to random_id.user-password.hex, but this is not working for me. When I don't provide a password for a user in that list of maps, I receive an invalid value error for the variable. Since I now have to provide a password key to the user maps, the following lookup never reaches the "default" option.

resource "google_sql_user" "additional_users" {
  for_each  = local.users
  project     = var.project_id
  name        = each.value.name
  password = lookup(each.value, "password", random_id.user-password.hex)
  instance   = google_sql_database_instance.default.name
  depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
}

Ulminator avatar May 26 '21 23:05 Ulminator

Have you tried setting the value to null? Like this:

additional_users = [{name: "test", password: null}]

morgante avatar May 27 '21 04:05 morgante

Yeah when I tried that earlier it failed as well with this error message:

Error: Error, failed to insert user test_user into instance test_instance: googleapi: Error 400: Invalid request: Missing user password for PostgreSQL instance., invalid

  on main.tf line 171, in resource "google_sql_user" "additional_users":
 171: resource "google_sql_user" "additional_users" {

Ulminator avatar May 27 '21 04:05 Ulminator

Interesting, this is definitely a bug then. null should be sufficient to accept the default.

We'll put it on the queue, but would also be happy to review a PR.

morgante avatar May 27 '21 04:05 morgante

I am working on this bug. This issue is only fixed in postgres module but still exist in mysql and mssql module.

ravisiddhu avatar Dec 06 '22 15:12 ravisiddhu

Fixed in #398

imrannayer avatar Jul 17 '23 21:07 imrannayer