» google_sql_user

Creates a new Google SQL User on a Google SQL User Instance. For more information, see the official documentation, or the JSON API.

» Example Usage

Example creating a SQL User.

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

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

  settings {
    tier = "D0"
  }
}

resource "google_sql_user" "users" {
  name     = "me"
  instance = "${google_sql_database_instance.master.name}"
  host     = "me.com"
  password = "changeme"
}

» Argument Reference

The following arguments are supported:

  • instance - (Required) The name of the Cloud SQL instance. Changing this forces a new resource to be created.

  • name - (Required) The name of the user. Changing this forces a new resource to be created.

  • password - (Optional) The password for the user. Can be updated.


  • host - (Optional) The host the user can connect from. This is only supported for MySQL instances. Don't set this field for PostgreSQL instances. Can be an IP address. Changing this forces a new resource to be created.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

» Attributes Reference

Only the arguments listed above are exposed as attributes.

» Import

SQL users for MySQL databases can be imported using the project, instance, host and name, e.g.

$ terraform import google_sql_user.users my-project/master-instance/my-domain.com/me

SQL users for PostgreSQL databases can be imported using the project, instance and name, e.g.

$ terraform import google_sql_user.users my-project/master-instance/me