/terraform-google-alloy-db

CFT terraform module for Alloy DB

Primary LanguageHCLApache License 2.0Apache-2.0

terraform-google-alloy-db

This module handles Google Cloud Platform AlloyDB cluster creation and configuration with Automated Backup Policy, Primary node instance and Read Node Pools. The resource/resources that this module will create are:

  • Creates an AlloyDB Cluster with/without automated backup policy
  • Creates a Primary Instance
  • Creates a pool of Read Instances

Usage

  • Usage of this module for creating a AlloyDB Cluster with a scheduled automated backup policy
module "alloy-db" {
  source               = "../.."
  cluster_id           = "alloydb-cluster"
  cluster_location     = "us-central1"
  project_id           = <"PROJECT_ID">
  cluster_labels       = {}
  cluster_display_name = ""
  cluster_initial_user = {
    user     = "<USER_NAME>",
    password = "<PASSWORD>"
  }
  network_self_link = "projects/${project_id}/global/networks/${network_name}"

  automated_backup_policy = {
    location      = "us-central1"
    backup_window = "1800s",
    enabled       = true,
    weekly_schedule = {
      days_of_week = ["FRIDAY"],
      start_times  = ["2:00:00:00", ]
    }
    quantity_based_retention_count = 1,
    time_based_retention_count     = null,
    labels = {
      test = "alloydb-cluster"
    },
  }
  primary_instance = null

  read_pool_instance = null

  depends_on = [google_compute_network.default, google_compute_global_address.private_ip_alloc, google_service_networking_connection.vpc_connection]
}
  • Usage of this module for creating a AlloyDB Cluster with a primary instance
module "alloy-db" {
  source               = "../.."
  project_id           = <PROJECT_ID>
  cluster_id           = "alloydb-cluster-with-primary-instance"
  cluster_location     = "us-central1"
  cluster_labels       = {}
  cluster_display_name = ""
  cluster_initial_user = {
    user     = "<USER_NAME>",
    password = "<PASSWORD>"
  }
  network_self_link = "projects/${project_id}/global/networks/${network_name}"

  automated_backup_policy = null

  primary_instance = {
    instance_id       = "primary-instance",
    instance_type     = "PRIMARY",
    machine_cpu_count = 2,
    database_flags    = {},
    display_name      = "alloydb-primary-instance"
  }
  read_pool_instance = null

  depends_on = [google_compute_network.default, google_compute_global_address.private_ip_alloc, google_service_networking_connection.vpc_connection]
}

Functional examples are included in the examples directory.

Inputs

Name Description Type Default Required
automated_backup_policy The automated backup policy for this cluster.
object({
location = optional(string),
backup_window = optional(string),
enabled = optional(bool),
weekly_schedule = object({
days_of_week = optional(list(string)),
start_times = list(string),
}),
quantity_based_retention_count = optional(number),
time_based_retention_count = optional(string),
labels = optional(map(string))
})
{
"backup_window": "1800s",
"enabled": false,
"labels": {
"test": "alloydb-cluster"
},
"location": "us-central1",
"quantity_based_retention_count": 1,
"time_based_retention_count": "null",
"weekly_schedule": {
"days_of_week": [
"FRIDAY"
],
"start_times": [
"2:00:00:00"
]
}
}
no
cluster_display_name Display Name for Alloy DB Cluster string "" no
cluster_id Configuration of the AlloyDb cluster. string n/a yes
cluster_initial_user Alloy DB Cluster Initial User Credentials
object({
user = optional(string),
password = string
})
{
"password": "alloydb-cluster-full",
"user": "alloydb-cluster-full"
}
no
cluster_labels Labels to identify the Alloy DB Cluster map(string) {} no
cluster_location Location where AlloyDb cluster will be deployed. string "us-central1" no
network_self_link Network ID where the AlloyDb cluster will be deployed. string n/a yes
primary_instance Primary cluster configuration that supports read and write operations.
object({
instance_id = string,
instance_type = string,
machine_cpu_count = number,
display_name = string,
database_flags = map(string)
})
n/a yes
project_id The ID of the project in which to provision resources. string n/a yes
read_pool_instance List of Read Pool Instances to be created
list(object({
instance_id = string,
display_name = string,
instance_type = string,
node_count = number,
database_flags = map(string),
availability_type = string,
ZONE = string,
machine_cpu_count = number
}))
[] no

Outputs

Name Description
cluster_id ID of the Alloy DB Cluster created
primary_instance_id ID of the primary instance created
read_instance_ids IDs of the read instances created

Requirements

These sections describe requirements for using this module.

Software

The following dependencies must be available:

Service Account

A service account with the following roles must be used to provision the resources of this module:

  • Storage Admin: roles/alloydb.admin

The Project Factory module and the IAM module may be used in combination to provision a service account with the necessary roles applied.

APIs

A project with the following APIs enabled must be used to host the resources of this module:

  • alloydb.googleapis.com

The Project Factory module can be used to provision a project with the necessary APIs enabled.

Contributing

Refer to the contribution guidelines for information on contributing to this module.

Security Disclosures

Please see our security disclosure process.