google_sql_database

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

Open in Cloud Shell

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"
}
Open in Cloud Shell

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:


Attributes Reference

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

Timeouts

This resource provides the following Timeouts configuration options:

Import

Database can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Database using one of the formats above. For example:

import {
  id = "projects/{{project}}/instances/{{instance}}/databases/{{name}}"
  to = google_sql_database.default
}

When using the terraform import command, 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.