-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4941c2
commit 4e3a399
Showing
9 changed files
with
1,182 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# AlloyDB module | ||
|
||
This module manages the creation of an AlloyDB cluster and instance with potential read replicas and an advanced cross region replication setup for disaster recovery scenarios. | ||
It can also create an initial set of users via the `users` parameters. | ||
|
||
Note that this module assumes that some options are the same for both the primary instance and the secondary one in case of cross regional replication configuration. | ||
|
||
*Warning:* if you use the `users` field, you terraform state will contain each user's password in plain text. | ||
|
||
<!-- TOC --> | ||
* [AlloyDB module](#alloydb-module) | ||
* [Examples](#examples) | ||
* [Simple example](#simple-example) | ||
* [Cross region replication](#cross-region-replication) | ||
* [Variables](#variables) | ||
* [Outputs](#outputs) | ||
<!-- TOC --> | ||
|
||
## Examples | ||
### Simple example | ||
|
||
This example shows how to setup a project, VPC and AlloyDB cluster and instance. | ||
|
||
```hcl | ||
module "project" { | ||
source = "./fabric/modules/project" | ||
billing_account = var.billing_account_id | ||
parent = var.folder_id | ||
name = "alloydb-prj" | ||
prefix = var.prefix | ||
services = [ | ||
"servicenetworking.googleapis.com", | ||
"alloydb.googleapis.com", | ||
] | ||
} | ||
module "vpc" { | ||
source = "./fabric/modules/net-vpc" | ||
project_id = module.project.project_id | ||
name = "my-network" | ||
# need only one - psa_config or subnets_psc | ||
psa_configs = [{ | ||
ranges = { alloydb = "10.60.0.0/16" } | ||
deletion_policy = "ABANDON" | ||
}] | ||
subnets_psc = [ | ||
{ | ||
ip_cidr_range = "10.0.3.0/24" | ||
name = "psc" | ||
region = var.region | ||
} | ||
] | ||
} | ||
module "alloydb" { | ||
source = "./fabric/modules/alloydb" | ||
project_id = module.project.project_id | ||
cluster_name = "db" | ||
cluster_network_config = { | ||
network = module.vpc.id | ||
} | ||
name = "db" | ||
location = var.region | ||
} | ||
# tftest modules=3 resources=14 inventory=simple.yaml e2e | ||
``` | ||
|
||
### Cross region replication | ||
|
||
```hcl | ||
module "alloydb" { | ||
source = "./fabric/modules/alloydb" | ||
project_id = var.project_id | ||
cluster_name = "db" | ||
cluster_network_config = { | ||
network = var.vpc.self_link | ||
} | ||
name = "db" | ||
location = "europe-west8" | ||
cross_region_replication = { | ||
enabled = true | ||
region = "europe-west12" | ||
} | ||
} | ||
# tftest modules=1 resources=4 inventory=cross_region_replication.yaml e2e | ||
``` | ||
<!-- BEGIN TFDOC --> | ||
## Variables | ||
|
||
| name | description | type | required | default | | ||
|---|---|:---:|:---:|:---:| | ||
| [cluster_name](variables.tf#L85) | Name of the primary cluster. | <code>string</code> | ✓ | | | ||
| [cluster_network_config](variables.tf#L90) | Network configuration for the cluster. Only one between cluster_network_config and cluster_psc_config can be used. | <code title="object({ network = string allocated_ip_range = optional(string, null) })">object({…})</code> | ✓ | | | ||
| [location](variables.tf#L196) | Region or zone of the cluster and instance. | <code>string</code> | ✓ | | | ||
| [name](variables.tf#L252) | Name of primary instance. | <code>string</code> | ✓ | | | ||
| [project_id](variables.tf#L267) | The ID of the project where this instances will be created. | <code>string</code> | ✓ | | | ||
| [automated_backup_configuration](variables.tf#L17) | Automated backup settings for cluster. | <code title="object({ enabled = optional(bool, false) backup_window = optional(string, "1800s") location = optional(string) weekly_schedule = optional(object({ days_of_week = optional(list(string), [ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY" ]) start_times = optional(object({ hours = optional(number, 23) minutes = optional(number, 0) seconds = optional(number, 0) nanos = optional(number, 0) }), {}) }), {}) retention_count = optional(number, 7) retention_period = optional(string, null) })">object({…})</code> | | <code title="{ enabled = false backup_window = "1800s" location = null weekly_schedule = { days_of_week = ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"] start_times = { hours = 23 minutes = 0 seconds = 0 nanos = 0 } } retention_count = 7 retention_period = null }">{…}</code> | | ||
| [availability_type](variables.tf#L68) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | <code>string</code> | | <code>"REGIONAL"</code> | | ||
| [client_connection_config](variables.tf#L74) | Client connection config. | <code title="object({ require_connectors = optional(bool, false) ssl_config = optional(object({ ssl_mode = string }), null) })">object({…})</code> | | <code>null</code> | | ||
| [continuous_backup_configuration](variables.tf#L99) | Continuous backup settings for cluster. | <code title="object({ enabled = optional(bool, false) recovery_window_days = optional(number, 14) })">object({…})</code> | | <code title="{ enabled = false recovery_window_days = 14 }">{…}</code> | | ||
| [cross_region_replication](variables.tf#L112) | Cross region replication config. | <code title="object({ enabled = optional(bool, false) promote_secondary = optional(bool, false) region = optional(string, null) })">object({…})</code> | | <code>{}</code> | | ||
| [database_version](variables.tf#L126) | Database type and version to create. | <code>string</code> | | <code>"POSTGRES_15"</code> | | ||
| [deletion_policy](variables.tf#L132) | AlloyDB cluster and instance deletion policy. | <code>string</code> | | <code>null</code> | | ||
| [encryption_config](variables.tf#L138) | Set encryption configuration. KMS name format: 'projects/[PROJECT]/locations/[REGION]/keyRings/[RING]/cryptoKeys/[KEY_NAME]'. | <code title="object({ primary_kms_key_name = string secondary_kms_key_name = optional(string, null) })">object({…})</code> | | <code>null</code> | | ||
| [flags](variables.tf#L148) | Map FLAG_NAME=>VALUE for database-specific tuning. | <code>map(string)</code> | | <code>null</code> | | ||
| [initial_user](variables.tf#L155) | AlloyDB cluster initial user credentials. | <code title="object({ user = optional(string, "root") password = string })">object({…})</code> | | <code>null</code> | | ||
| [insights_config](variables.tf#L164) | Query Insights configuration. Defaults to null which disables Query Insights. | <code title="object({ query_string_length = optional(number, 1024) record_application_tags = optional(bool, false) record_client_address = optional(bool, false) query_plans_per_minute = optional(number, 5) })">object({…})</code> | | <code>null</code> | | ||
| [instance_network_config](variables.tf#L175) | Network configuration for the instance. Only one between instance_network_config and instance_psc_config can be used. | <code title="object({ authorized_external_networks = list(string) enable_public_ip = bool })">object({…})</code> | | <code>null</code> | | ||
| [labels](variables.tf#L190) | Labels to be attached to all instances. | <code>map(string)</code> | | <code>null</code> | | ||
| [machine_config](variables.tf#L201) | AlloyDB machine config. | <code title="object({ cpu_count = optional(number, 2) })">object({…})</code> | | <code title="{ cpu_count = 2 }">{…}</code> | | ||
| [maintenance_config](variables.tf#L212) | Set maintenance window configuration. | <code title="object({ enabled = optional(bool, false) day = optional(string, "SUNDAY") start_time = optional(object({ hours = optional(number, 23) minutes = optional(number, 0) seconds = optional(number, 0) nanos = optional(number, 0) }), {}) })">object({…})</code> | | <code title="{ enabled = false day = "SUNDAY" start_time = { hours = 23 minutes = 0 seconds = 0 nanos = 0 } }">{…}</code> | | ||
| [prefix](variables.tf#L257) | Optional prefix used to generate instance names. | <code>string</code> | | <code>null</code> | | ||
| [query_insights_config](variables.tf#L272) | Query insights config. | <code title="object({ query_string_length = optional(number, 1024) record_application_tags = optional(bool, true) record_client_address = optional(bool, true) query_plans_per_minute = optional(number, 5) })">object({…})</code> | | <code title="{ query_string_length = 1024 record_application_tags = true record_client_address = true query_plans_per_minute = 5 }">{…}</code> | | ||
| [users](variables.tf#L288) | Map of users to create in the primary instance (and replicated to other replicas). Set PASSWORD to null if you want to get an autogenerated password. The user types available are: 'ALLOYDB_BUILT_IN' or 'ALLOYDB_IAM_USER'. | <code title="map(object({ password = optional(string) roles = optional(list(string), ["alloydbsuperuser"]) type = optional(string) }))">map(object({…}))</code> | | <code>null</code> | | ||
|
||
## Outputs | ||
|
||
| name | description | sensitive | | ||
|---|---|:---:| | ||
| [id](outputs.tf#L25) | Fully qualified primary instance id. | | | ||
| [ids](outputs.tf#L30) | Fully qualified ids of all instances. | | | ||
| [instances](outputs.tf#L38) | AlloyDB instance resources. | ✓ | | ||
| [ip](outputs.tf#L44) | IP address of the primary instance. | | | ||
| [ips](outputs.tf#L49) | IP addresses of all instances. | | | ||
| [name](outputs.tf#L56) | Name of the primary instance. | | | ||
| [names](outputs.tf#L61) | Names of all instances. | | | ||
| [user_passwords](outputs.tf#L69) | Map of containing the password of all users created through terraform. | ✓ | | ||
<!-- END TFDOC --> |
Oops, something went wrong.