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
resource "google_sql_database" "database" {
name = "mysql_correa_integrationtest_db"
instance = google_sql_database_instance.instance.name
}
resource "google_sql_database" "database2" {
Parameters
-
charset
optional computed - string
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 computed - string
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.
-
name
required - string
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.
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.
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.