Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_sql_user error on creating postgresql #3848

Closed
roger-rainey opened this issue Jun 13, 2019 · 2 comments · Fixed by GoogleCloudPlatform/magic-modules#1922
Closed

google_sql_user error on creating postgresql #3848

roger-rainey opened this issue Jun 13, 2019 · 2 comments · Fixed by GoogleCloudPlatform/magic-modules#1922
Assignees
Labels

Comments

@roger-rainey
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

Terraform v0.11.14

Affected Resource(s)

  • google_sql_user

Terraform Configuration Files

### Module code

resource "google_sql_database_instance" "new_instance_sql" {
  provider         = "google-beta"
  depends_on       = ["google_service_networking_connection.private_vpc_connection"]
  name             = "${local.name_prefix}"
  region           = "${var.general["region"]}"
  database_version = "${lookup(var.general, "db_version", "MYSQL_5_7")}"
  project          = "${data.terraform_remote_state.project.project}"

  settings {
    tier                        = "${lookup(var.instance, "tier", "db-f1-micro")}"
    disk_type                   = "${lookup(var.instance, "disk_type", "PD_SSD")}"
    disk_size                   = "${lookup(var.instance, "disk_size", 10)}"
    disk_autoresize             = "${lookup(var.instance, "disk_auto", true)}"
    activation_policy           = "${lookup(var.instance, "activation_policy", "ALWAYS")}"
    availability_type           = "${lookup(var.instance, "availability_type", "ZONAL")}"
    authorized_gae_applications = "${var.authorized_gae_applications}"
    user_labels                 = "${var.labels}"

    ip_configuration {
      require_ssl     = "${lookup(var.instance, "require_ssl", false)}"
      ipv4_enabled    = "${lookup(var.instance, "ipv4_enabled", false)}"
      private_network = "projects/${data.terraform_remote_state.project.project}/global/networks/${data.terraform_remote_state.network.network_name}"
    }

    location_preference {
      zone = "${var.general["region"]}-${var.instance["zone"]}"
    }

    backup_configuration {
      binary_log_enabled = false
      enabled            = "${lookup(var.general, "backup_enabled", true)}"
      start_time         = "${lookup(var.general, "backup_time", "02:30")}" # every 2:30AM
    }

    maintenance_window {
      day          = "${lookup(var.instance, "maintenance_day", 1)}"          # Monday
      hour         = "${lookup(var.instance, "maintenance_hour", 2)}"         # 2AM
      update_track = "${lookup(var.instance, "maintenance_track", "stable")}"
    }
  }
}

resource "random_id" "username" {
  byte_length = 4
}

resource "random_id" "password" {
  byte_length = 8
}

resource "google_sql_user" "user" {
  name     = "${random_id.username.hex}"
  instance = "${google_sql_database_instance.new_instance_sql.name}"
  host     = "%"
  password = "${random_id.password.hex}"
  project  = "${data.terraform_remote_state.project.project}"
}

Input being sent to module

general {
name = "pgdatabase"
env = "development"
db_version = "POSTGRES_9_6"
region = "us-east1"
}

instance {
zone = "b"
}
database_name = "pgdatabase"

Debug Output

https://gist.github.com/roger-rainey/72543f562bda749ef22bcfbdab88246b

Panic Output

Expected Behavior

It should have been able to retrieve the google_sql_user.user.name and google_sql_user.user.password values. This works when using mysql.

Actual Behavior

The values google_sql_user.user.name and google_sql_user.user.password are not available even though they were actually created and are used in the cloud sql instance.

Steps to Reproduce

  1. terragrunt apply

Important Factoids

Using terragrunt, which is also why I am on the terraform version above.

References

  • #0000
@ghost ghost added the bug label Jun 13, 2019
@emilymye emilymye self-assigned this Jun 17, 2019
@emilymye
Copy link
Contributor

emilymye commented Jun 17, 2019

This is due to the fact that the module is providing "%" for the host, which is only valid for MySQL users. While we should (and will) fix the issue causing this provider issue, it's hard for us to validate the value of host since it relies on a value in a different resource, and so we can't really validate this request before it's made. So, here's what we should do:

  1. I'll fix an issue that causes this "provider error".
  2. I'll fill an issue against the Cloud SQL API so they reject creation of a Postgres user with a non-empty host.
  3. You will need to explicitly set host to an empty string (to avoid a permadiff) until (and if) item 2 is fixed (1 will not fix this). This might require your module's owner to fix how they generate the host value;

@ghost
Copy link

ghost commented Jul 18, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants