The module creates and manages Cloud SQL instance with one of the supported SQL database engines:

  • PostgreSQL
  • MySQL

Key features:

  • Cloud SQL instance creation
  • databases configuration
  • database user creation
  • firewall configuration

Managed databases in Cloud SQL

Deploys Cloud SQL managed instance for MySQL or PostgreSQL engine in GCP
$650
BUY
314
Log in to Corewide IaC registry

Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:

 shellterraform login solutions.corewide.com
Provision instructions

Initialize mandatory providers:

Copy and paste into your Terraform configuration and insert the variables:

 hclmodule "tf_gcp_cloudsql" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-cloudsql/google"
  version = "~> 1.0.0"

  # specify module inputs here or try one of the examples below
  ...
}

Initialize the setup:

 shellterraform init
Define update strategy

Corewide DevOps team strictly follows Semantic Versioning Specification to provide our clients with products that have predictable upgrades between versions. We recommend pinning patch versions of our modules using pessimistic constraint operator (~>) to prevent breaking changes during upgrades.

To get new features during the upgrades (without breaking compatibility), use ~> 1.0 and run terraform init -upgrade

For the safest setup, use strict pinning with version = "1.0.0"

v1.0.0 released 4 months, 4 weeks ago
New version approx. every 4 weeks

Create highly available Cloud SQL instance with a PostgreSQL custom engine with 14 version, disabled backups, custom user with password, create 2 databases and firewall for database instance:

 hclmodule "sql_db" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-cloudsql/google"
  version = "~> 1.0"

  db_engine        = "postgres"
  name_prefix      = "foo"
  engine_version   = "14"
  multi_az_enabled = true

  backup_configuration = {
    enabled = false
  }

  user = {
    name     = "myuser"
    password = "securepassword123"
  }

  maintenance_window = {
    day  = 2
    hour = 3
  }

  databases = [
    {
      name = "backend"
    },
    {
      name = "frontend"
    },
  ]

  authorized_networks = [
    {
      name  = "office"
      value = "97.3.24.256/32"
    },
    {
      name  = "home"
      value = "173.162.256.78/32"
    },
  ]
}

Create Cloud SQL instance with MySQL engine and default values:

 hclmodule "sql_db" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-cloudsql/google"
  version = "~> 1.0"

  name_prefix = "foo"
  db_engine   = "mysql"
}
Variable Description Type Default Required Sensitive
db_engine Cloud SQL instance engine. Supported engines are: postgres and mysql string yes no
engine_version Cloud SQL instance engine version. Possible values for MySQL: 8.0, 8.4, for PostgreSQL: 12, 13, 14, 15, 16 and 17 string yes no
name_prefix Name prefix for Cloud SQL istance string yes no
authorized_networks List of authorized networks objects list(object) [] no no
authorized_networks[*].name Name of authorized network string no no
authorized_networks[*].value CIDR of authorized network string no no
backup_configuration Cloud SQL instance backup configuration object {} no no
backup_configuration.enabled Whether to enable backups on Cloud SQL instance. Enforced to true, if multi_az_enabled is set to true bool true no no
backup_configuration.hour Backup start time in format of 24 hour string 3 no no
backup_configuration.retention_units Number of backups to keep before deleting number 5 no no
databases List of database objects to create list(object) [] no no
databases[*].charset Database charset. If not specified, these values are considered as default: utf8mb4 for MySQL and utf8 for PostgreSQL string no no
databases[*].collation Database collation. If not specified, these values are considered as default: utf8mb4_general_ci for MySQL and en_US.utf8 for PostgreSQL string no no
databases[*].name Database name string yes no
deletion_protection_enabled Enables deletion protection of the primary Cloud SQL instance bool true no no
machine_size Cloud SQL instance machine size string db-f1-micro no no
machine_storage_size Cloud SQL instance disk size in GB number 10 no no
maintenance_window Cloud SQL maintenance window parameters object {} no no
maintenance_window.day Day of the week in numbers format (1 - Monday) number 3 no no
maintenance_window.hour Start hour for maintenance window in 24-hour format number 2 no no
multi_az_enabled Enables High Availability for the primary Cloud SQL instance bool false no no
region GCP region to create resources in. Default GCP provider region used if not specified string no no
user User to create in database object {} no no
user.name Name of a user to be created string admin no no
user.password Password for the user, will be generated randomly if not provided string no no
Output Description Type Sensitive
connection_parameters Cloud SQL instance connection parameters map yes
primary Attributes of Cloud SQL instance resource yes
Dependency Version Kind
terraform >= 1.3 CLI
hashicorp/google ~> 6.2 provider
hashicorp/random ~> 3.3 provider

Not sure where to start?
Let's find your perfect match.