2015-10-23 14:10:41 +00:00
|
|
|
---
|
|
|
|
layout: "google"
|
|
|
|
page_title: "Google: google_sql_database"
|
2017-08-07 17:13:55 +00:00
|
|
|
sidebar_current: "docs-google-sql-database-x"
|
2015-10-23 14:10:41 +00:00
|
|
|
description: |-
|
|
|
|
Creates a new SQL database in Google Cloud SQL.
|
|
|
|
---
|
|
|
|
|
|
|
|
# google\_sql\_database
|
|
|
|
|
2017-08-10 20:28:52 +00:00
|
|
|
Creates a new Google SQL Database on a Google SQL Database 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/databases).
|
2015-10-23 14:10:41 +00:00
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
|
|
|
Example creating a SQL Database.
|
|
|
|
|
2017-04-17 10:17:54 +00:00
|
|
|
```hcl
|
2015-10-23 14:10:41 +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"
|
|
|
|
}
|
2015-10-23 14:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_sql_database" "users" {
|
2017-07-17 15:32:29 +00:00
|
|
|
name = "users-db"
|
|
|
|
instance = "${google_sql_database_instance.master.name}"
|
|
|
|
charset = "latin1"
|
|
|
|
collation = "latin1_swedish_ci"
|
2015-10-23 14:10:41 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Argument Reference
|
|
|
|
|
|
|
|
The following arguments are supported:
|
|
|
|
|
|
|
|
* `name` - (Required) The name of the database.
|
|
|
|
|
|
|
|
* `instance` - (Required) The name of containing instance.
|
|
|
|
|
2016-04-10 21:34:15 +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.
|
|
|
|
|
2017-08-10 20:28:52 +00:00
|
|
|
* `charset` - (Optional) The charset value. See MySQL's
|
|
|
|
[Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html)
|
|
|
|
and Postgres' [Character Set Support](https://www.postgresql.org/docs/9.6/static/multibyte.html)
|
|
|
|
for more details and supported values. Postgres databases are in [Beta](/docs/providers/google/index.html#beta-features),
|
|
|
|
and have limited `charset` support; they only support a value of `UTF8` at creation time.
|
|
|
|
|
|
|
|
* `collation` - (Optional) The collation value. See MySQL's
|
|
|
|
[Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html)
|
|
|
|
and Postgres' [Collation Support](https://www.postgresql.org/docs/9.6/static/collation.html)
|
|
|
|
for more details and supported values. Postgres databases are in [Beta](/docs/providers/google/index.html#beta-features),
|
|
|
|
and have limited `collation` support; they only support a value of `en_US.UTF8` at creation time.
|
2017-07-17 15:32:29 +00:00
|
|
|
|
2015-10-23 14:10:41 +00:00
|
|
|
## Attributes Reference
|
|
|
|
|
2016-04-10 21:34:15 +00:00
|
|
|
In addition to the arguments listed above, the following computed attributes are
|
|
|
|
exported:
|
2015-10-23 14:10:41 +00:00
|
|
|
|
|
|
|
* `self_link` - The URI of the created resource.
|
2017-06-22 16:13:05 +00:00
|
|
|
|
|
|
|
## Import
|
|
|
|
|
2018-08-28 23:51:37 +00:00
|
|
|
SQL databases can be imported using one of any of these accepted formats:
|
2017-06-22 16:13:05 +00:00
|
|
|
|
|
|
|
```
|
2018-08-28 23:51:37 +00:00
|
|
|
$ terraform import google_sql_database.database projects/{{project}}/instances/{{instance}}/databases/{{name}}
|
|
|
|
$ terraform import google_sql_database.database {{project}}/{{instance}}/{{name}}
|
|
|
|
$ terraform import google_sql_database.database instances/{{name}}/databases/{{name}}
|
|
|
|
$ terraform import google_sql_database.database {{instance}}/{{name}}
|
|
|
|
$ terraform import google_sql_database.database {{name}}
|
|
|
|
|
2017-06-22 16:13:05 +00:00
|
|
|
```
|