Skip to content

Latest commit

 

History

History
159 lines (120 loc) · 5.81 KB

sql_database.html.markdown

File metadata and controls

159 lines (120 loc) · 5.81 KB
subcategory page_title description
Cloud SQL
Google: google_sql_database
Represents a SQL database inside the Cloud SQL instance, hosted in Google's cloud.

google_sql_database

Represents a SQL database inside the Cloud SQL instance, hosted in Google's cloud.

## Example Usage - Sql Database Basic
resource "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"
}
## Example Usage - Sql Database Deletion Policy
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"
}

Argument Reference

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 of UTF8 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 of en_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".

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format projects/{{project}}/instances/{{instance}}/databases/{{name}}
  • self_link - The URI of the created resource.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

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}}

User Project Overrides

This resource supports User Project Overrides.