Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
simonebruzzechesse committed May 17, 2024
1 parent 11e1f73 commit d65f3af
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
12 changes: 8 additions & 4 deletions modules/alloydb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Note that this module assumes that some options are the same for both the primar
* [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 -->
Expand Down Expand Up @@ -72,11 +74,11 @@ module "alloydb" {
source = "./fabric/modules/alloydb"
project_id = var.project_id
cluster_name = "db"
cluster_network_config = {
location = var.region
name = "db"
network_config = {
network = var.vpc.self_link
}
name = "db"
location = "europe-west8"
cross_region_replication = {
enabled = true
region = "europe-west12"
Expand Down Expand Up @@ -164,7 +166,9 @@ module "alloydb" {
| [maintenance_config](variables.tf#L184) | Set maintenance window configuration. | <code title="object&#40;&#123;&#10; enabled &#61; optional&#40;bool, false&#41;&#10; day &#61; optional&#40;string, &#34;SUNDAY&#34;&#41;&#10; start_time &#61; optional&#40;object&#40;&#123;&#10; hours &#61; optional&#40;number, 23&#41;&#10; minutes &#61; optional&#40;number, 0&#41;&#10; seconds &#61; optional&#40;number, 0&#41;&#10; nanos &#61; optional&#40;number, 0&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; enabled &#61; false&#10; day &#61; &#34;SUNDAY&#34;&#10; start_time &#61; &#123;&#10; hours &#61; 23&#10; minutes &#61; 0&#10; seconds &#61; 0&#10; nanos &#61; 0&#10; &#125;&#10;&#125;">&#123;&#8230;&#125;</code> |
| [prefix](variables.tf#L244) | Optional prefix used to generate instance names. | <code>string</code> | | <code>null</code> |
| [query_insights_config](variables.tf#L259) | Query insights config. | <code title="object&#40;&#123;&#10; query_string_length &#61; optional&#40;number, 1024&#41;&#10; record_application_tags &#61; optional&#40;bool, true&#41;&#10; record_client_address &#61; optional&#40;bool, true&#41;&#10; query_plans_per_minute &#61; optional&#40;number, 5&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code title="&#123;&#10; query_string_length &#61; 1024&#10; record_application_tags &#61; true&#10; record_client_address &#61; true&#10; query_plans_per_minute &#61; 5&#10;&#125;">&#123;&#8230;&#125;</code> |
| [users](variables.tf#L275) | 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&#40;object&#40;&#123;&#10; password &#61; optional&#40;string&#41;&#10; roles &#61; optional&#40;list&#40;string&#41;, &#91;&#34;alloydbsuperuser&#34;&#93;&#41;&#10; type &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>null</code> |
| [secondary_cluster_name](variables.tf#L275) | Name of secondary cluster instance. | <code>string</code> | | <code>null</code> |
| [secondary_name](variables.tf#L281) | Name of secondary instance. | <code>string</code> | | <code>null</code> |
| [users](variables.tf#L287) | 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&#40;object&#40;&#123;&#10; password &#61; optional&#40;string&#41;&#10; roles &#61; optional&#40;list&#40;string&#41;, &#91;&#34;alloydbsuperuser&#34;&#93;&#41;&#10; type &#61; optional&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>null</code> |

## Outputs

Expand Down
9 changes: 5 additions & 4 deletions modules/alloydb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ locals {
is_regional = var.availability_type == "REGIONAL" ? true : false
# secondary instance type is aligned with cluster type unless apply is targeting a promotion, in that
# case cluster will be 'primary' while instance still 'secondary'.
secondary_cluster_name = coalesce(var.secondary_cluster_name, "${var.cluster_name}-sec")
secondary_instance_name = coalesce(var.secondary_name, "${var.name}-sec")
secondary_instance_type = try(var.cross_region_replication.promote_secondary && google_alloydb_cluster.secondary[0].cluster_type == "SECONDARY" ? "SECONDARY" : google_alloydb_cluster.secondary[0].cluster_type, null)

users = {
for k, v in coalesce(var.users, {}) :
k => {
Expand Down Expand Up @@ -189,7 +190,7 @@ resource "google_alloydb_instance" "primary" {
resource "google_alloydb_cluster" "secondary" {
count = var.cross_region_replication.enabled ? 1 : 0
project = var.project_id
cluster_id = "${local.prefix}${var.cluster_name}-secondary"
cluster_id = local.secondary_cluster_name
cluster_type = var.cross_region_replication.promote_secondary ? "PRIMARY" : "SECONDARY"
database_version = var.database_version
deletion_policy = "FORCE"
Expand Down Expand Up @@ -301,9 +302,9 @@ resource "google_alloydb_instance" "secondary" {
availability_type = var.availability_type
cluster = google_alloydb_cluster.secondary[0].id
database_flags = var.cross_region_replication.promote_secondary ? var.flags : null
display_name = "${local.prefix}${var.name}"
display_name = local.secondary_instance_name
gce_zone = local.is_regional ? null : var.gce_zone
instance_id = "${local.prefix}${var.name}-secondary"
instance_id = local.secondary_instance_name
instance_type = local.secondary_instance_type
labels = var.labels

Expand Down
12 changes: 12 additions & 0 deletions modules/alloydb/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ variable "query_insights_config" {
}
}

variable "secondary_cluster_name" {
description = "Name of secondary cluster instance."
type = string
default = null
}

variable "secondary_name" {
description = "Name of secondary instance."
type = string
default = null
}

variable "users" {
description = "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'."
type = map(object({
Expand Down
22 changes: 17 additions & 5 deletions tests/modules/alloydb/examples/cross_region_replication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ values:
annotations: null
cluster_id: db
cluster_type: PRIMARY
continuous_backup_config:
- enabled: true
encryption_config: []
recovery_window_days: 14
database_version: POSTGRES_15
deletion_policy: DEFAULT
display_name: null
Expand All @@ -36,8 +40,12 @@ values:
timeouts: null
module.alloydb.google_alloydb_cluster.secondary[0]:
annotations: null
cluster_id: db-secondary
cluster_id: db-sec
cluster_type: SECONDARY
continuous_backup_config:
- enabled: true
encryption_config: []
recovery_window_days: 14
database_version: POSTGRES_15
deletion_policy: FORCE
display_name: null
Expand Down Expand Up @@ -66,7 +74,9 @@ values:
labels: null
machine_config:
- cpu_count: 2
network_config: []
network_config:
- authorized_external_networks: []
enable_public_ip: false
query_insights_config:
- query_plans_per_minute: 5
query_string_length: 1024
Expand All @@ -77,14 +87,16 @@ values:
module.alloydb.google_alloydb_instance.secondary[0]:
annotations: null
availability_type: REGIONAL
display_name: db
display_name: db-sec
gce_zone: null
instance_id: db-secondary
instance_id: db-sec
instance_type: SECONDARY
labels: null
machine_config:
- cpu_count: 2
network_config: []
network_config:
- authorized_external_networks: []
enable_public_ip: false
query_insights_config:
- query_plans_per_minute: 5
query_string_length: 1024
Expand Down

0 comments on commit d65f3af

Please sign in to comment.