OpenMCF logoOpenMCF

Loading...

GCP AlloyDB Cluster

Deploys an AlloyDB cluster with a bundled primary instance, automated and continuous backup policies, optional CMEK encryption at three levels (data, backups, PITR), and VPC-based private networking via Private Service Access. The primary instance is bundled because a cluster without one cannot serve queries.

What Gets Created

When you deploy a GcpAlloydbCluster resource, OpenMCF provisions:

  • AlloyDB Cluster — a google_alloydb_cluster resource in the specified region with network configuration, backup policies, encryption, and maintenance settings
  • Primary Instance — a google_alloydb_instance of type PRIMARY attached to the cluster, with configurable machine size, availability type, query insights, and client connection settings
  • Automated Backup Policy — created only when automatedBackupPolicy is specified, configures periodic snapshot backups with retention and schedule settings
  • Continuous Backup — enabled by default with 14-day PITR window, configurable via continuousBackupConfig
  • CMEK Encryption — created only when kmsKeyName fields are specified, encrypts cluster data, backup snapshots, and continuous backup data independently

Prerequisites

  • GCP credentials configured via service account key or OpenMCF provider config
  • A VPC network with Private Service Access configured (the network must have a private services connection to servicenetworking.googleapis.com)
  • A GCP project with the AlloyDB API enabled (alloydb.googleapis.com)
  • A Cloud KMS key if enabling CMEK encryption (must be in the same region as the cluster)

Quick Start

Create a file alloydb.yaml:

apiVersion: gcp.openmcf.org/v1
kind: GcpAlloydbCluster
metadata:
  name: my-alloydb
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: my-project
    pulumi.openmcf.org/stack.name: dev.GcpAlloydbCluster.my-alloydb
spec:
  projectId:
    value: my-gcp-project
  clusterName: my-alloydb-cluster
  location: us-central1
  network:
    value: projects/my-gcp-project/global/networks/default
  primaryInstance:
    instanceId: my-primary
    cpuCount: 2
    availabilityType: ZONAL

Deploy:

openmcf apply -f alloydb.yaml

This creates an AlloyDB cluster with a 2-CPU primary instance in us-central1, connected to the default VPC with GCP-managed encryption and default backup policies.

Configuration Reference

Required Fields

FieldTypeDescriptionValidation
projectIdStringValueOrRefGCP project where the cluster is created. Can reference a GcpProject resource via valueFrom.Required
clusterNamestringName of the AlloyDB cluster. Becomes the GCP resource ID. Immutable after creation.Pattern: ^[a-z][a-z0-9-]{0,61}[a-z0-9]$, 2-63 chars
locationstringGCP region (e.g., us-central1). Immutable after creation.Required
networkStringValueOrRefVPC network with Private Service Access. Can reference a GcpVpc resource via valueFrom. Immutable after creation.Required
primaryInstance.instanceIdstringName of the primary instance. Immutable after creation.Pattern: ^[a-z][a-z0-9-]{0,61}[a-z0-9]$, 2-63 chars

Optional Fields

FieldTypeDefaultDescription
allocatedIpRangestring—Named IP range for Private Service Access. Use when IP ranges are pre-planned.
databaseVersionstringLatestPostgreSQL version: POSTGRES_14, POSTGRES_15, or POSTGRES_16.
displayNamestring—Human-readable name for the cluster.
initialUser.passwordstring—Initial superuser password. Min 8 characters. Required when initialUser is set.
initialUser.userstringpostgresInitial superuser name.
automatedBackupPolicy.enabledbooltrueEnable or disable automated periodic backups.
automatedBackupPolicy.backupWindowstring3600sBackup window duration in seconds (e.g., 3600s).
automatedBackupPolicy.locationstringSame as clusterRegion where backups are stored.
automatedBackupPolicy.quantityBasedRetentionCountint—Number of backups to retain. Mutually exclusive with timeBasedRetentionPeriod.
automatedBackupPolicy.timeBasedRetentionPeriodstring—Retention duration (e.g., 1209600s for 14 days). Mutually exclusive with quantityBasedRetentionCount.
automatedBackupPolicy.weeklySchedule.daysOfWeekstring[]DailyDays to run backups: MONDAY through SUNDAY.
automatedBackupPolicy.weeklySchedule.startHourint—UTC hour (0-23) to start backups.
automatedBackupPolicy.encryptionKmsKeyNameStringValueOrRefGoogle-managedKMS key for backup encryption. Can reference GcpKmsKey via valueFrom.
continuousBackupConfig.enabledbooltrueEnable continuous backup for PITR.
continuousBackupConfig.recoveryWindowDaysint14PITR recovery window in days (1-35).
continuousBackupConfig.encryptionKmsKeyNameStringValueOrRefGoogle-managedKMS key for continuous backup encryption.
kmsKeyNameStringValueOrRefGoogle-managedKMS key for cluster data-at-rest encryption. Immutable. Can reference GcpKmsKey via valueFrom.
maintenanceWindow.daystringGCP-selectedDay of week: MONDAY through SUNDAY.
maintenanceWindow.startHourintGCP-selectedUTC hour (0-23) for maintenance start.
deletionProtectionbooltruePrevents accidental cluster destruction.
primaryInstance.cpuCountint—Number of CPUs. Mutually exclusive with machineType.
primaryInstance.machineTypestring—Machine type (e.g., n2-highmem-4). Mutually exclusive with cpuCount.
primaryInstance.availabilityTypestringGCP defaultZONAL or REGIONAL. REGIONAL provides automatic failover.
primaryInstance.databaseFlagsmap<string,string>{}PostgreSQL configuration flags.
primaryInstance.displayNamestring—Human-readable name for the instance.
primaryInstance.queryInsightsConfig.queryPlansPerMinuteint5Plans captured per minute (0-20).
primaryInstance.queryInsightsConfig.queryStringLengthint1024Max query string length (256-4500).
primaryInstance.queryInsightsConfig.recordApplicationTagsbooltrueRecord application tags in insights.
primaryInstance.queryInsightsConfig.recordClientAddressbooltrueRecord client IP in insights.
primaryInstance.requireConnectorsboolfalseForce AlloyDB Auth Proxy for all connections.
primaryInstance.sslModestring—ENCRYPTED_ONLY or ALLOW_UNENCRYPTED_AND_ENCRYPTED.

Examples

Production HA Cluster

A production-ready cluster with REGIONAL availability, initial user, and deletion protection:

apiVersion: gcp.openmcf.org/v1
kind: GcpAlloydbCluster
metadata:
  name: prod-alloydb
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: infra
    pulumi.openmcf.org/stack.name: prod.GcpAlloydbCluster.prod-alloydb
spec:
  projectId:
    value: prod-project
  clusterName: prod-alloydb-cluster
  location: us-central1
  network:
    value: projects/prod-project/global/networks/prod-vpc
  databaseVersion: POSTGRES_16
  deletionProtection: true
  initialUser:
    password: "change-me-immediately"
    user: dbadmin
  primaryInstance:
    instanceId: prod-primary
    cpuCount: 4
    availabilityType: REGIONAL
    sslMode: ENCRYPTED_ONLY

Enterprise CMEK Encryption

Full CMEK coverage with separate keys for data, backups, and PITR:

apiVersion: gcp.openmcf.org/v1
kind: GcpAlloydbCluster
metadata:
  name: enterprise-alloydb
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: infra
    pulumi.openmcf.org/stack.name: prod.GcpAlloydbCluster.enterprise-alloydb
spec:
  projectId:
    value: enterprise-project
  clusterName: enterprise-alloydb
  location: us-east1
  network:
    valueFrom:
      kind: GcpVpc
      name: enterprise-vpc
  databaseVersion: POSTGRES_16
  kmsKeyName:
    valueFrom:
      kind: GcpKmsKey
      name: alloydb-data-key
  automatedBackupPolicy:
    enabled: true
    timeBasedRetentionPeriod: "2592000s"
    encryptionKmsKeyName:
      valueFrom:
        kind: GcpKmsKey
        name: alloydb-backup-key
  continuousBackupConfig:
    enabled: true
    recoveryWindowDays: 21
    encryptionKmsKeyName:
      valueFrom:
        kind: GcpKmsKey
        name: alloydb-pitr-key
  primaryInstance:
    instanceId: enterprise-primary
    cpuCount: 8
    availabilityType: REGIONAL
    requireConnectors: true
    sslMode: ENCRYPTED_ONLY
    queryInsightsConfig:
      queryPlansPerMinute: 10
      queryStringLength: 4096
      recordApplicationTags: true
      recordClientAddress: true

Custom Backup Policy

Quantity-based retention with a weekly schedule:

apiVersion: gcp.openmcf.org/v1
kind: GcpAlloydbCluster
metadata:
  name: backup-alloydb
  labels:
    openmcf.org/provisioner: pulumi
    pulumi.openmcf.org/organization: my-org
    pulumi.openmcf.org/project: infra
    pulumi.openmcf.org/stack.name: staging.GcpAlloydbCluster.backup-alloydb
spec:
  projectId:
    value: staging-project
  clusterName: backup-alloydb
  location: europe-west1
  network:
    value: projects/staging-project/global/networks/staging-vpc
  automatedBackupPolicy:
    enabled: true
    quantityBasedRetentionCount: 10
    backupWindow: "7200s"
    weeklySchedule:
      daysOfWeek:
        - MONDAY
        - WEDNESDAY
        - FRIDAY
      startHour: 3
  maintenanceWindow:
    day: SUNDAY
    startHour: 4
  primaryInstance:
    instanceId: backup-primary
    cpuCount: 4
    availabilityType: REGIONAL

Stack Outputs

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

OutputTypeDescription
cluster_idstringFully qualified cluster resource name: projects/{p}/locations/{l}/clusters/{c}
cluster_namestringShort cluster name (same as clusterName input)
primary_instance_ipstringPrivate IP of the primary instance. Connect on port 5432.
primary_instance_namestringFully qualified instance resource name. Used for Auth Proxy connections.
database_versionstringComputed PostgreSQL version (e.g., POSTGRES_15)
statestringCluster state: READY, CREATING, MAINTENANCE, etc.

Related Components

  • GcpVpc — VPC network with Private Service Access for cluster connectivity
  • GcpKmsKey — CMEK encryption keys for data, backups, and continuous backups
  • GcpKmsKeyRing — Key ring containing KMS keys (must be in the same region as the cluster)
  • GcpServiceAccount — Service account for application-level IAM access to AlloyDB
  • GcpFirewallRule — Network-level access control for AlloyDB connectivity

Next article

GCP Artifact Registry Repo

GCP Artifact Registry Repo Deploys a Google Cloud Artifact Registry repository with configurable format, region, and access control. The component creates the repository along with dedicated reader and writer GCP service accounts with appropriate IAM bindings, and optionally enables unauthenticated public access for open-source artifact distribution. What Gets Created When you deploy a GcpArtifactRegistryRepo resource, OpenMCF provisions: Artifact Registry Repository — a repository in the...
Read next article
Presets
3 ready-to-deploy configurationsView presets →