Skip to content

googleSqlDatabase

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

Example Usage - Sql Database Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleSqlDatabaseInstanceInstance =
  new google.sqlDatabaseInstance.SqlDatabaseInstance(this, "instance", {
    database_version: "MYSQL_8_0",
    deletion_protection: "true",
    name: "my-database-instance",
    region: "us-central1",
    settings: [
      {
        tier: "db-f1-micro",
      },
    ],
  });
new google.sqlDatabase.SqlDatabase(this, "database", {
  instance: googleSqlDatabaseInstanceInstance.name,
  name: "my-database",
});

Example Usage - Sql Database Deletion Policy

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleSqlDatabaseInstanceInstance =
  new google.sqlDatabaseInstance.SqlDatabaseInstance(this, "instance", {
    database_version: "POSTGRES_14",
    deletion_protection: "true",
    name: "my-database-instance",
    region: "us-central1",
    settings: [
      {
        tier: "db-g1-small",
      },
    ],
  });
new google.sqlDatabase.SqlDatabase(this, "database_deletion_policy", {
  deletion_policy: "ABANDON",
  instance: googleSqlDatabaseInstanceInstance.name,
  name: "my-database",
});

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 enUsUtf8 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.

  • deletionPolicy - (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}}
  • selfLink - 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.