subcategory | page_title | description |
---|---|---|
Cloud SQL |
Google: google_sql_database |
Represents a SQL database inside the Cloud SQL instance, hosted in
Google's cloud. |
Represents a SQL database inside the Cloud SQL instance, hosted in Google's cloud.
## Example Usage - Sql Database Basicresource "google_sql_database" "database" {
name = "my-database"
instance = google_sql_database_instance.instance.name
}
# See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
resource "google_sql_database_instance" "instance" {
name = "my-database-instance"
region = "us-central1"
database_version = "MYSQL_8_0"
settings {
tier = "db-f1-micro"
}
deletion_protection = "true"
}
resource "google_sql_database" "database_deletion_policy" {
name = "my-database"
instance = google_sql_database_instance.instance.name
deletion_policy = "ABANDON"
}
# See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
resource "google_sql_database_instance" "instance" {
name = "my-database-instance"
region = "us-central1"
database_version = "POSTGRES_14"
settings {
tier = "db-g1-small"
}
deletion_protection = "true"
}
The following arguments are supported:
-
name
- (Required) The name of the database in the Cloud SQL instance. This does not include the project ID or instance name. -
instance
- (Required) The name of the Cloud SQL instance. This does not include the project ID.
-
charset
- (Optional) The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value ofUTF8
at creation time. -
collation
- (Optional) The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value ofen_US.UTF8
at creation time. -
project
- (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. -
deletion_policy
- (Optional) The deletion policy for the database. Setting ABANDON allows the resource to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be deleted from the API if there are users other than cloudsqlsuperuser with access. Possible values are: "ABANDON".
In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with formatprojects/{{project}}/instances/{{instance}}/databases/{{name}}
self_link
- The URI of the created resource.
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.
Database can be imported using any of these accepted formats:
$ terraform import google_sql_database.default projects/{{project}}/instances/{{instance}}/databases/{{name}}
$ terraform import google_sql_database.default instances/{{instance}}/databases/{{name}}
$ terraform import google_sql_database.default {{project}}/{{instance}}/{{name}}
$ terraform import google_sql_database.default {{instance}}/{{name}}
$ terraform import google_sql_database.default {{name}}
This resource supports User Project Overrides.