| --- |
| # ---------------------------------------------------------------------------- |
| # |
| # *** AUTO GENERATED CODE *** Type: MMv1 *** |
| # |
| # ---------------------------------------------------------------------------- |
| # |
| # This file is automatically generated by Magic Modules and manual |
| # changes will be clobbered when the file is regenerated. |
| # |
| # Please read more about how to change this file in |
| # .github/CONTRIBUTING.md. |
| # |
| # ---------------------------------------------------------------------------- |
| subcategory: "Cloud SQL" |
| description: |- |
| 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. |
| |
| |
| |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=sql_database_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Sql Database Basic |
| |
| |
| ```hcl |
| 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" |
| } |
| ``` |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=sql_database_deletion_policy&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Sql Database Deletion Policy |
| |
| |
| ```hcl |
| 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](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 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 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", "DELETE". Defaults to "DELETE". |
| |
| |
| ## 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](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-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: |
| |
| * `projects/{{project}}/instances/{{instance}}/databases/{{name}}` |
| * `instances/{{instance}}/databases/{{name}}` |
| * `{{project}}/{{instance}}/{{name}}` |
| * `{{instance}}/{{name}}` |
| * `{{name}}` |
| |
| |
| In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Database using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "projects/{{project}}/instances/{{instance}}/databases/{{name}}" |
| to = google_sql_database.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Database can be imported using one of the formats above. For example: |
| |
| ``` |
| $ 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |