google_alloydb_cluster

A managed alloydb cluster.

To get more information about Cluster, see:

Open in Cloud Shell

Example Usage - Alloydb Cluster Basic

resource "google_alloydb_cluster" "default" {
  cluster_id = "alloydb-cluster"
  location   = "us-central1"
  network    = google_compute_network.default.id
}

data "google_project" "project" {}

resource "google_compute_network" "default" {
  name = "alloydb-cluster"
}
Open in Cloud Shell

Example Usage - Alloydb Cluster Full

resource "google_alloydb_cluster" "full" {
  cluster_id   = "alloydb-cluster-full"
  location     = "us-central1"
  network      = google_compute_network.default.id
  database_version = "POSTGRES_15"

  initial_user {
    user     = "alloydb-cluster-full"
    password = "alloydb-cluster-full"
  }

  continuous_backup_config {
    enabled              = true
    recovery_window_days = 14
  }

  automated_backup_policy {
    location      = "us-central1"
    backup_window = "1800s"
    enabled       = true

    weekly_schedule {
      days_of_week = ["MONDAY"]

      start_times {
        hours   = 23
        minutes = 0
        seconds = 0
        nanos   = 0
      }
    }

    quantity_based_retention {
      count = 1
    }

    labels = {
      test = "alloydb-cluster-full"
    }
  }

  labels = {
    test = "alloydb-cluster-full"
  }
}

data "google_project" "project" {}

resource "google_compute_network" "default" {
  name = "alloydb-cluster-full"
}

Example Usage - Alloydb Cluster Restore

resource "google_alloydb_cluster" "source" {
  cluster_id = "alloydb-source-cluster"
  location   = "us-central1"
  network    = data.google_compute_network.default.id

  initial_user {
    password = "alloydb-source-cluster"
  }
}

resource "google_alloydb_instance" "source" {
  cluster       = google_alloydb_cluster.source.name
  instance_id   = "alloydb-instance"
  instance_type = "PRIMARY"

  machine_config {
    cpu_count = 2
  }

  depends_on = [google_service_networking_connection.vpc_connection]
}

resource "google_alloydb_backup" "source" {
  backup_id    = "alloydb-backup"
  location     = "us-central1"
  cluster_name = google_alloydb_cluster.source.name

  depends_on = [google_alloydb_instance.source]
}

resource "google_alloydb_cluster" "restored_from_backup" {
  cluster_id            = "alloydb-backup-restored"
  location              = "us-central1"
  network               = data.google_compute_network.default.id
  restore_backup_source {
    backup_name = google_alloydb_backup.source.name
  }
}

resource "google_alloydb_cluster" "restored_via_pitr" {
  cluster_id             = "alloydb-pitr-restored"
  location               = "us-central1"
  network                = data.google_compute_network.default.id

  restore_continuous_backup_source {
    cluster = google_alloydb_cluster.source.name
    point_in_time = "2023-08-03T19:19:00.094Z"
  }
}

data "google_project" "project" {}

data "google_compute_network" "default" {
  name = "alloydb-network"
}

resource "google_compute_global_address" "private_ip_alloc" {
  name          =  "alloydb-source-cluster"
  address_type  = "INTERNAL"
  purpose       = "VPC_PEERING"
  prefix_length = 16
  network       = data.google_compute_network.default.id
}

resource "google_service_networking_connection" "vpc_connection" {
  network                 = data.google_compute_network.default.id
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}

Example Usage - Alloydb Secondary Cluster Basic

resource "google_alloydb_cluster" "primary" {
  cluster_id = "alloydb-primary-cluster"
  location   = "us-central1"
  network    = google_compute_network.default.id
}

resource "google_alloydb_instance" "primary" {
  cluster       = google_alloydb_cluster.primary.name
  instance_id   = "alloydb-primary-instance"
  instance_type = "PRIMARY"

  machine_config {
    cpu_count = 2
  }

  depends_on = [google_service_networking_connection.vpc_connection]
}

resource "google_alloydb_cluster" "secondary" {
  cluster_id   = "alloydb-secondary-cluster"
  location     = "us-east1"
  network      = google_compute_network.default.id
  cluster_type = "SECONDARY"

  continuous_backup_config {
    enabled = false
  }

  secondary_config {
    primary_cluster_name = google_alloydb_cluster.primary.name
  }

  depends_on = [google_alloydb_instance.primary]
}

data "google_project" "project" {}

resource "google_compute_network" "default" {
  name = "alloydb-secondary-cluster"
}

resource "google_compute_global_address" "private_ip_alloc" {
  name          =  "alloydb-secondary-cluster"
  address_type  = "INTERNAL"
  purpose       = "VPC_PEERING"
  prefix_length = 16
  network       = google_compute_network.default.id
}

resource "google_service_networking_connection" "vpc_connection" {
  network                 = google_compute_network.default.id
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}

Argument Reference

The following arguments are supported:


The encryption_config block supports:

The network_config block supports:

The initial_user block supports:

The restore_backup_source block supports:

The restore_continuous_backup_source block supports:

The continuous_backup_config block supports:

The encryption_config block supports:

The automated_backup_policy block supports:

The encryption_config block supports:

The weekly_schedule block supports:

The start_times block supports:

The time_based_retention block supports:

The quantity_based_retention block supports:

The secondary_config block supports:

The maintenance_update_policy block supports:

The maintenance_windows block supports:

The start_time block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

The encryption_info block contains:

The continuous_backup_info block contains:

The encryption_info block contains:

The backup_source block contains:

The migration_source block contains:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Cluster can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Cluster using one of the formats above. For example:

import {
  id = "projects/{{project}}/locations/{{location}}/clusters/{{cluster_id}}"
  to = google_alloydb_cluster.default
}

When using the terraform import command, Cluster can be imported using one of the formats above. For example:

$ terraform import google_alloydb_cluster.default projects/{{project}}/locations/{{location}}/clusters/{{cluster_id}}
$ terraform import google_alloydb_cluster.default {{project}}/{{location}}/{{cluster_id}}
$ terraform import google_alloydb_cluster.default {{location}}/{{cluster_id}}
$ terraform import google_alloydb_cluster.default {{cluster_id}}

User Project Overrides

This resource supports User Project Overrides.