Google Cloud SQL Database

This page shows how to write Terraform for Cloud SQL Database and write them securely.

google_sql_database (Terraform)

The Database in Cloud SQL can be configured in Terraform with the resource name google_sql_database. The following sections describe 1 example of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L13
resource "google_sql_database" "database" {
  name     = "mysql_correa_integrationtest_db"
  instance = google_sql_database_instance.instance.name
}

resource "google_sql_database" "database2" {

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

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.

The name of the Cloud SQL instance. This does not include the project ID.

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

Explanation in Terraform Registry

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

Tips: Best Practices for The Other Google Cloud SQL Resources

In addition to the google_sql_database_instance, Google Cloud SQL has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

google_sql_database_instance

Ensure to disable local_infile setting in MySQL

It is better to disable the local_infile setting in MySQL. If this is not disabled, arbitrary files might be readable.

Review your Google Cloud SQL settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Frequently asked questions

What is Google Cloud SQL Database?

Google Cloud SQL Database is a resource for Cloud SQL of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud SQL Database?

For Terraform, the ronaldofc/db-terraform source code example is useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.