2016-01-13 21:33:08 +00:00
---
layout: "google"
page_title: "Google: google_sql_user"
sidebar_current: "docs-google-sql-user"
description: |-
Creates a new SQL user in Google Cloud SQL.
---
# google\_sql\_user
Creates a new Google SQL User on a Google SQL User Instance. For more information, see the [official documentation ](https://cloud.google.com/sql/ ), or the [JSON API ](https://cloud.google.com/sql/docs/admin-api/v1beta4/users ).
2017-03-29 09:37:36 +00:00
~> **Note:** All arguments including the username and password will be stored in the raw state as plain-text.
2017-05-22 20:43:11 +00:00
[Read more about sensitive data in state ](/docs/state/sensitive-data.html ). Passwords will not be retrieved when running
"terraform import".
2017-03-29 09:37:36 +00:00
2016-01-13 21:33:08 +00:00
## Example Usage
Example creating a SQL User.
2017-04-17 10:17:54 +00:00
```hcl
2016-01-13 21:33:08 +00:00
resource "google_sql_database_instance" "master" {
2016-04-10 21:34:15 +00:00
name = "master-instance"
2016-03-31 10:37:17 +00:00
2016-04-10 21:34:15 +00:00
settings {
tier = "D0"
}
2016-01-13 21:33:08 +00:00
}
resource "google_sql_user" "users" {
2016-04-10 21:34:15 +00:00
name = "me"
instance = "${google_sql_database_instance.master.name}"
host = "me.com"
2017-02-18 14:16:14 +00:00
password = "changeme"
2016-01-13 21:33:08 +00:00
}
```
## Argument Reference
The following arguments are supported:
2016-04-10 21:34:15 +00:00
* `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.
2016-01-13 21:33:08 +00:00
2018-02-07 20:02:01 +00:00
* `password` - (Optional) The password for the user. Can be updated.
2016-01-13 21:33:08 +00:00
2016-04-10 21:34:15 +00:00
- - -
2018-02-09 21:43:49 +00:00
* `host` - (Optional) The host the user can connect from. This is only supported
2018-06-11 20:47:01 +00:00
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.
2018-02-09 21:43:49 +00:00
2018-03-12 20:59:47 +00:00
* `project` - (Optional) The ID of the project in which the resource belongs. If it
2016-04-10 21:34:15 +00:00
is not provided, the provider project is used.
## Attributes Reference
Only the arguments listed above are exposed as attributes.
2017-05-22 20:43:11 +00:00
2017-06-14 00:02:27 +00:00
## Import
2017-05-22 20:43:11 +00:00
2018-12-12 17:06:36 +00:00
SQL users for MySQL databases can be imported using the `project` , `instance` , `host` and `name` , e.g.
2018-02-09 21:43:49 +00:00
```
2018-12-12 17:06:36 +00:00
$ terraform import google_sql_user.users my-project/master-instance/my-domain.com/me
2018-02-09 21:43:49 +00:00
```
2018-12-12 17:06:36 +00:00
SQL users for PostgreSQL databases can be imported using the `project` , `instance` and `name` , e.g.
2017-05-22 20:43:11 +00:00
```
2018-12-12 17:06:36 +00:00
$ terraform import google_sql_user.users my-project/master-instance/me
2017-06-14 00:02:27 +00:00
```