OpenMCF logoOpenMCF

Loading...

GCP Cloud SQL

Deploys a Google Cloud SQL instance with configurable database engine (MySQL or PostgreSQL), optional private IP networking, automated backups with point-in-time recovery, and regional high availability. The component provisions a single managed database instance with SSD storage and GCP-managed labels.

What Gets Created

When you deploy a GcpCloudSql resource, OpenMCF provisions:

  • Cloud SQL Database Instance — a google_sql_database_instance with SSD storage, the specified machine tier, and database version, placed in the target GCP project and region
  • IP Configuration — public IPv4 connectivity by default, or private IP within a VPC when network.privateIpEnabled is true
  • Authorized Networks — created only when network.authorizedNetworks contains CIDR entries, allowing direct public IP access from those ranges
  • High Availability (Regional) — configured only when highAvailability.enabled is true, promoting the instance to REGIONAL availability with automatic failover to the specified secondary zone
  • Automated Backups — created only when backup.enabled is true, with configurable retention and optional point-in-time recovery
  • Database Flags — applied only when databaseFlags entries are provided, passing engine-specific tuning parameters to the instance

Prerequisites

  • GCP credentials configured via environment variables or OpenMCF provider config
  • A GCP project where the Cloud SQL instance will be created
  • A VPC network with Private Services Access configured if enabling private IP connectivity
  • Service Networking API enabled in the project if using private IP

Quick Start

Create a file cloudsql.yaml:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudSql
metadata:
  name: my-db
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpCloudSql.my-db
spec:
  projectId: my-gcp-project
  region: us-central1
  databaseEngine: POSTGRESQL
  databaseVersion: POSTGRES_15
  tier: db-n1-standard-1
  storageGb: 10

Deploy:

openmcf apply -f cloudsql.yaml

This creates a PostgreSQL 15 instance on a db-n1-standard-1 machine with 10 GB SSD storage, public IP enabled, and no high availability.

Configuration Reference

Required Fields

FieldTypeDescriptionValidation
projectIdstringGCP project ID where the instance is created. Can reference a GcpProject resource via valueFrom.Required
regionstringGCP region for the instance (e.g., us-central1).Pattern: ^[a-z]+-[a-z]+[0-9]$
databaseEngineenumDatabase engine type. Valid values: MYSQL, POSTGRESQL.Must be specified (cannot be DATABASE_ENGINE_UNSPECIFIED)
databaseVersionstringEngine-specific version string (e.g., MYSQL_8_0, POSTGRES_15).Minimum length: 1
tierstringMachine type for the instance (e.g., db-n1-standard-1, db-custom-2-8192).Minimum length: 1
storageGbint32Storage size in gigabytes.10–65536. Recommended default: 10

Optional Fields

FieldTypeDefaultDescription
diskAutoresizebooltrueAutomatically increase storage when approaching capacity.
editionenumENTERPRISECloud SQL edition. ENTERPRISE: standard, 99.95% SLA for HA instances. ENTERPRISE_PLUS: premium, 99.99% SLA, faster reads.
deletionProtectionboolfalsePrevents accidental deletion of the instance when enabled.
queryInsightsEnabledboolfalseEnables Query Insights for performance monitoring and query analysis.
rootPasswordstring—Initial root password for the instance. Minimum length: 8 characters.
databaseFlagsmap<string, string>{}Engine-specific configuration flags as key-value pairs (e.g., max_connections: "200").
network.vpcIdstring—VPC network ID for private IP connectivity. Can reference a GcpVpc resource via valueFrom.
network.privateIpEnabledboolfalseEnables private IP for the instance. Requires network.vpcId to be set.
network.ipv4EnabledboolfalseEnables public IPv4 for the instance. Can be combined with private IP.
network.authorizedNetworksstring[][]CIDR blocks allowed to connect via public IP. Must be unique. Pattern: x.x.x.x/x.
highAvailability.enabledboolfalseEnables regional high availability with automatic failover. Requires highAvailability.zone.
highAvailability.zonestring—Secondary zone for HA failover (e.g., us-central1-b). Required when highAvailability.enabled is true.
backup.enabledboolfalseEnables automated daily backups. Requires backup.startTime and backup.retentionDays.
backup.startTimestring—Daily backup window start time in HH:MM format (UTC). Required when backup is enabled.
backup.retentionDaysint327Number of days to retain backups. Range: 1–365.
backup.pointInTimeRecoveryEnabledboolfalseEnables PITR using transaction logs. Requires backup.enabled to be true.
maintenanceWindow.dayint32—Day of week for maintenance (1=Monday, 7=Sunday).
maintenanceWindow.hourint32—Hour for maintenance start (0–23, UTC).
maintenanceWindow.updateTrackstring—Update track: canary for early updates, stable for production.

Examples

MySQL with Public IP

A MySQL 8.0 instance with public IP access restricted to a single office CIDR:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudSql
metadata:
  name: app-mysql
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpCloudSql.app-mysql
spec:
  projectId: my-gcp-project
  region: us-central1
  databaseEngine: MYSQL
  databaseVersion: MYSQL_8_0
  tier: db-n1-standard-2
  storageGb: 20
  network:
    ipv4Enabled: true
    authorizedNetworks:
      - 203.0.113.0/24

PostgreSQL with Private IP and Backups

A PostgreSQL instance accessible only within a VPC, with daily backups and point-in-time recovery:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudSql
metadata:
  name: api-postgres
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: staging.GcpCloudSql.api-postgres
spec:
  projectId: my-gcp-project
  region: us-central1
  databaseEngine: POSTGRESQL
  databaseVersion: POSTGRES_15
  tier: db-custom-2-8192
  storageGb: 50
  network:
    vpcId: projects/my-gcp-project/global/networks/my-vpc
    privateIpEnabled: true
  backup:
    enabled: true
    startTime: "03:00"
    retentionDays: 14
    pointInTimeRecoveryEnabled: true

Production HA with Full Configuration

A production-grade PostgreSQL instance with high availability, Enterprise Plus edition, backups, scheduled maintenance, and custom database flags:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudSql
metadata:
  name: prod-postgres
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: prod.GcpCloudSql.prod-postgres
spec:
  projectId: my-gcp-project
  region: us-central1
  databaseEngine: POSTGRESQL
  databaseVersion: POSTGRES_15
  tier: db-custom-4-16384
  storageGb: 200
  diskAutoresize: true
  edition: ENTERPRISE_PLUS
  deletionProtection: true
  queryInsightsEnabled: true
  rootPassword: my-secure-root-pw
  network:
    vpcId: projects/my-gcp-project/global/networks/prod-vpc
    privateIpEnabled: true
  highAvailability:
    enabled: true
    zone: us-central1-b
  backup:
    enabled: true
    startTime: "02:00"
    retentionDays: 30
    pointInTimeRecoveryEnabled: true
  maintenanceWindow:
    day: 7
    hour: 4
    updateTrack: stable
  databaseFlags:
    max_connections: "200"
    log_min_duration_statement: "1000"

Using Foreign Key References

Reference other OpenMCF-managed resources instead of hardcoding IDs:

apiVersion: gcp.openmcf.org/v1
kind: GcpCloudSql
metadata:
  name: ref-postgres
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: prod.GcpCloudSql.ref-postgres
spec:
  projectId:
    valueFrom:
      kind: GcpProject
      name: my-project
      field: status.outputs.project_id
  region: us-central1
  databaseEngine: POSTGRESQL
  databaseVersion: POSTGRES_15
  tier: db-n1-standard-2
  storageGb: 50
  network:
    vpcId:
      valueFrom:
        kind: GcpVpc
        name: my-vpc
        field: status.outputs.network_id
    privateIpEnabled: true
  backup:
    enabled: true
    startTime: "03:00"
    retentionDays: 7

Stack Outputs

After deployment, the following outputs are available in status.outputs:

OutputTypeDescription
instance_namestringName of the Cloud SQL instance
connection_namestringFull connection name in the format project:region:instance, used by Cloud SQL Proxy
private_ipstringPrivate IP address of the instance (only set when network.privateIpEnabled is true)
public_ipstringPublic IP address of the instance
self_linkstringGCP resource self link for the Cloud SQL instance

Related Components

  • GcpProject — provides the GCP project where the instance is created
  • GcpVpc — provides the VPC network for private IP connectivity

Next article

GCP Cloud Tasks Queue

GCP Cloud Tasks Queue Deploys a GCP Cloud Tasks queue with configurable dispatch rate limits, retry policies, and optional queue-level HTTP target configuration with OIDC or OAuth authentication. Cloud Tasks queues do not support GCP labels. What Gets Created When you deploy a GcpCloudTasksQueue resource, OpenMCF provisions: Cloud Tasks Queue — a googlecloudtasksqueue resource in the specified project and region with the configured dispatch and retry settings Rate Limits — created only when...
Read next article
Presets
3 ready-to-deploy configurationsView presets →