-
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.
* add alloydb module --------- Co-authored-by: Ludovico Magnocavallo <[email protected]>
- Loading branch information
1 parent
10ae9bc
commit 1e149c1
Showing
13 changed files
with
1,486 additions
and
144 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
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,191 @@ | ||
# AlloyDB module | ||
|
||
This module manages the creation of an AlloyDB cluster. It also supports cross-region replication scenario by setting up a secondary cluster. | ||
It can also create an initial set of users via the `users` variable. | ||
|
||
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) | ||
* [Custom flags and users definition](#custom-flags-and-users-definition) | ||
* [CMEK encryption](#cmek-encryption) | ||
* [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" | ||
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" | ||
location = var.region | ||
name = "db" | ||
network_config = { | ||
network = var.vpc.self_link | ||
} | ||
cross_region_replication = { | ||
enabled = true | ||
region = "europe-west12" | ||
} | ||
} | ||
# tftest modules=1 resources=4 inventory=cross_region_replication.yaml e2e | ||
``` | ||
|
||
In a cross-region replication scenario (like in the previous example) this module also supports [promoting the secondary instance](https://cloud.google.com/alloydb/docs/cross-region-replication/work-with-cross-region-replication#promote-secondary-cluster) to become a primary instance via the `var.cross_region_replication.promote_secondary` flag. | ||
|
||
### Custom flags and users definition | ||
|
||
```hcl | ||
module "alloydb" { | ||
source = "./fabric/modules/alloydb" | ||
project_id = var.project_id | ||
cluster_name = "primary" | ||
location = var.region | ||
name = "primary" | ||
flags = { | ||
"alloydb.enable_pgaudit" = "on" | ||
"alloydb.iam_authentication" = "on" | ||
idle_in_transaction_session_timeout = "900000" | ||
timezone = "'UTC'" | ||
} | ||
network_config = { | ||
network = var.vpc.self_link | ||
} | ||
users = { | ||
# generate a password for user1 | ||
user1 = { | ||
password = null | ||
} | ||
# assign a password to user2 | ||
user2 = { | ||
password = "mypassword" | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=5 inventory=custom.yaml e2e | ||
``` | ||
|
||
### CMEK encryption | ||
|
||
```hcl | ||
module "alloydb" { | ||
source = "./fabric/modules/alloydb" | ||
project_id = var.project_id | ||
cluster_name = "primary" | ||
location = var.region | ||
name = "primary" | ||
network_config = { | ||
network = var.vpc.self_link | ||
} | ||
encryption_config = { | ||
primary_kms_key_name = var.kms_key.id | ||
} | ||
} | ||
# tftest modules=1 resources=2 inventory=cmek.yaml e2e | ||
``` | ||
<!-- BEGIN TFDOC --> | ||
## Variables | ||
|
||
| name | description | type | required | default | | ||
|---|---|:---:|:---:|:---:| | ||
| [cluster_name](variables.tf#L99) | Name of the primary cluster. | <code>string</code> | ✓ | | | ||
| [location](variables.tf#L186) | Region or zone of the cluster and instance. | <code>string</code> | ✓ | | | ||
| [name](variables.tf#L242) | Name of primary instance. | <code>string</code> | ✓ | | | ||
| [network_config](variables.tf#L247) | Network configuration for cluster and instance. Only one between cluster_network_config and cluster_psc_config can be used. | <code title="object({ network = string allocated_ip_range = optional(string, null) authorized_external_networks = optional(list(string), null) enable_public_ip = optional(bool, false) })">object({…})</code> | ✓ | | | ||
| [project_id](variables.tf#L275) | The ID of the project where this instances will be created. | <code>string</code> | ✓ | | | ||
| [annotations](variables.tf#L17) | Map FLAG_NAME=>VALUE for annotations which allow client tools to store small amount of arbitrary data. | <code>map(string)</code> | | <code>null</code> | | ||
| [automated_backup_configuration](variables.tf#L23) | 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#L76) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | <code>string</code> | | <code>"REGIONAL"</code> | | ||
| [client_connection_config](variables.tf#L82) | Client connection config. | <code title="object({ require_connectors = optional(bool, false) ssl_config = optional(object({ ssl_mode = string }), null) })">object({…})</code> | | <code>null</code> | | ||
| [cluster_display_name](variables.tf#L93) | Display name of the primary cluster. | <code>string</code> | | <code>null</code> | | ||
| [continuous_backup_configuration](variables.tf#L104) | Continuous backup settings for cluster. | <code title="object({ enabled = optional(bool, false) recovery_window_days = optional(number, 14) })">object({…})</code> | | <code title="{ enabled = true recovery_window_days = 14 }">{…}</code> | | ||
| [cross_region_replication](variables.tf#L117) | 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#L131) | Database type and version to create. | <code>string</code> | | <code>"POSTGRES_15"</code> | | ||
| [deletion_policy](variables.tf#L137) | AlloyDB cluster and instance deletion policy. | <code>string</code> | | <code>null</code> | | ||
| [display_name](variables.tf#L143) | AlloyDB instance display name. | <code>string</code> | | <code>null</code> | | ||
| [encryption_config](variables.tf#L149) | 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#L159) | Map FLAG_NAME=>VALUE for database-specific tuning. | <code>map(string)</code> | | <code>null</code> | | ||
| [gce_zone](variables.tf#L165) | The GCE zone that the instance should serve from. This can ONLY be specified for ZONAL instances. If present for a REGIONAL instance, an error will be thrown. | <code>string</code> | | <code>null</code> | | ||
| [initial_user](variables.tf#L171) | AlloyDB cluster initial user credentials. | <code title="object({ user = optional(string, "root") password = string })">object({…})</code> | | <code>null</code> | | ||
| [labels](variables.tf#L180) | Labels to be attached to all instances. | <code>map(string)</code> | | <code>null</code> | | ||
| [machine_config](variables.tf#L191) | AlloyDB machine config. | <code title="object({ cpu_count = optional(number, 2) })">object({…})</code> | | <code title="{ cpu_count = 2 }">{…}</code> | | ||
| [maintenance_config](variables.tf#L202) | 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#L265) | Optional prefix used to generate instance names. | <code>string</code> | | <code>null</code> | | ||
| [query_insights_config](variables.tf#L280) | 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> | | ||
| [secondary_cluster_display_name](variables.tf#L296) | Display name of secondary cluster instance. | <code>string</code> | | <code>null</code> | | ||
| [secondary_cluster_name](variables.tf#L302) | Name of secondary cluster instance. | <code>string</code> | | <code>null</code> | | ||
| [secondary_display_name](variables.tf#L308) | Display name of secondary instance. | <code>string</code> | | <code>null</code> | | ||
| [secondary_name](variables.tf#L314) | Name of secondary instance. | <code>string</code> | | <code>null</code> | | ||
| [users](variables.tf#L320) | 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#L24) | Fully qualified primary instance id. | | | ||
| [ids](outputs.tf#L29) | Fully qualified ids of all instances. | | | ||
| [instances](outputs.tf#L37) | AlloyDB instance resources. | ✓ | | ||
| [ip](outputs.tf#L43) | IP address of the primary instance. | | | ||
| [ips](outputs.tf#L48) | IP addresses of all instances. | | | ||
| [name](outputs.tf#L55) | Name of the primary instance. | | | ||
| [names](outputs.tf#L60) | Names of all instances. | | | ||
| [secondary_id](outputs.tf#L68) | Fully qualified primary instance id. | | | ||
| [secondary_ip](outputs.tf#L73) | IP address of the primary instance. | | | ||
| [user_passwords](outputs.tf#L78) | Map of containing the password of all users created through terraform. | ✓ | | ||
<!-- END TFDOC --> |
Oops, something went wrong.