diff --git a/modules/alloydb/README.md b/modules/alloydb/README.md index 147fd0a46c..b8d286eafd 100644 --- a/modules/alloydb/README.md +++ b/modules/alloydb/README.md @@ -63,8 +63,8 @@ module "alloydb" { network = module.vpc.id } } - name = "db" - location = var.region + instance_name = "db" + location = var.region } # tftest modules=3 resources=16 inventory=simple.yaml e2e ``` @@ -73,11 +73,11 @@ module "alloydb" { ```hcl module "alloydb" { - source = "./fabric/modules/alloydb" - project_id = var.project_id - cluster_name = "db" - location = var.region - name = "db" + source = "./fabric/modules/alloydb" + project_id = var.project_id + cluster_name = "db" + location = var.region + instance_name = "db" network_config = { psa_config = { network = var.vpc.id @@ -98,11 +98,11 @@ In a cross-region replication scenario (like in the previous example) this modul ```hcl module "alloydb" { - source = "./fabric/modules/alloydb" - project_id = var.project_id - cluster_name = "db" - location = var.region - name = "db" + source = "./fabric/modules/alloydb" + project_id = var.project_id + cluster_name = "db" + location = var.region + instance_name = "db" network_config = { psc_config = { allowed_consumer_projects = [var.project_number] } } @@ -114,11 +114,11 @@ module "alloydb" { ```hcl module "alloydb" { - source = "./fabric/modules/alloydb" - project_id = var.project_id - cluster_name = "primary" - location = var.region - name = "primary" + source = "./fabric/modules/alloydb" + project_id = var.project_id + cluster_name = "primary" + location = var.region + instance_name = "primary" flags = { "alloydb.enable_pgaudit" = "on" "alloydb.iam_authentication" = "on" @@ -196,11 +196,11 @@ module "vpc" { module "alloydb" { - source = "./fabric/modules/alloydb" - project_id = module.project.project_id - cluster_name = "primary" - location = var.region - name = "primary" + source = "./fabric/modules/alloydb" + project_id = module.project.project_id + cluster_name = "primary" + location = var.region + instance_name = "primary" network_config = { psa_config = { network = module.vpc.id @@ -235,11 +235,11 @@ module "org" { } module "alloydb" { - source = "./fabric/modules/alloydb" - project_id = var.project_id - cluster_name = "primary" - location = var.region - name = "primary" + source = "./fabric/modules/alloydb" + project_id = var.project_id + cluster_name = "primary" + location = var.region + instance_name = "primary" network_config = { psa_config = { network = var.vpc.id @@ -257,35 +257,31 @@ module "alloydb" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| | [cluster_name](variables.tf#L99) | Name of the primary cluster. | string | ✓ | | -| [location](variables.tf#L186) | Region or zone of the cluster and instance. | string | ✓ | | -| [name](variables.tf#L242) | Name of primary instance. | string | ✓ | | -| [network_config](variables.tf#L247) | Network configuration for cluster and instance. Only one between psa_config and psc_config can be used. | object({…}) | ✓ | | -| [project_id](variables.tf#L290) | The ID of the project where this instances will be created. | string | ✓ | | +| [instance_name](variables.tf#L184) | Name of primary instance. | string | ✓ | | +| [location](variables.tf#L195) | Region or zone of the cluster and instance. | string | ✓ | | +| [network_config](variables.tf#L251) | Network configuration for cluster and instance. Only one between psa_config and psc_config can be used. | object({…}) | ✓ | | +| [project_id](variables.tf#L294) | The ID of the project where this instances will be created. | string | ✓ | | | [annotations](variables.tf#L17) | Map FLAG_NAME=>VALUE for annotations which allow client tools to store small amount of arbitrary data. | map(string) | | null | | [automated_backup_configuration](variables.tf#L23) | Automated backup settings for cluster. | object({…}) | | {…} | | [availability_type](variables.tf#L76) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | string | | "REGIONAL" | | [client_connection_config](variables.tf#L82) | Client connection config. | object({…}) | | null | | [cluster_display_name](variables.tf#L93) | Display name of the primary cluster. | string | | null | | [continuous_backup_configuration](variables.tf#L104) | Continuous backup settings for cluster. | object({…}) | | {…} | -| [cross_region_replication](variables.tf#L117) | Cross region replication config. | object({…}) | | {} | -| [database_version](variables.tf#L131) | Database type and version to create. | string | | "POSTGRES_15" | -| [deletion_policy](variables.tf#L137) | AlloyDB cluster and instance deletion policy. | string | | null | -| [display_name](variables.tf#L143) | AlloyDB instance display name. | string | | null | -| [encryption_config](variables.tf#L149) | Set encryption configuration. KMS name format: 'projects/[PROJECT]/locations/[REGION]/keyRings/[RING]/cryptoKeys/[KEY_NAME]'. | object({…}) | | null | -| [flags](variables.tf#L159) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null | -| [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. | string | | null | -| [initial_user](variables.tf#L171) | AlloyDB cluster initial user credentials. | object({…}) | | null | -| [labels](variables.tf#L180) | Labels to be attached to all instances. | map(string) | | null | -| [machine_config](variables.tf#L191) | AlloyDB machine config. | object({…}) | | {…} | -| [maintenance_config](variables.tf#L202) | Set maintenance window configuration. | object({…}) | | {…} | -| [prefix](variables.tf#L280) | Optional prefix used to generate instance names. | string | | null | -| [query_insights_config](variables.tf#L295) | Query insights config. | object({…}) | | {…} | -| [secondary_cluster_display_name](variables.tf#L311) | Display name of secondary cluster instance. | string | | null | -| [secondary_cluster_name](variables.tf#L317) | Name of secondary cluster instance. | string | | null | -| [secondary_display_name](variables.tf#L323) | Display name of secondary instance. | string | | null | -| [secondary_name](variables.tf#L329) | Name of secondary instance. | string | | null | -| [tag_bindings](variables.tf#L335) | Tag bindings for this service, in key => tag value id format. | map(string) | | {} | -| [users](variables.tf#L342) | 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'. | map(object({…})) | | null | +| [cross_region_replication](variables.tf#L117) | Cross region replication config. | object({…}) | | {} | +| [database_version](variables.tf#L135) | Database type and version to create. | string | | "POSTGRES_15" | +| [deletion_policy](variables.tf#L141) | AlloyDB cluster and instance deletion policy. | string | | null | +| [display_name](variables.tf#L147) | AlloyDB instance display name. | string | | null | +| [encryption_config](variables.tf#L153) | Set encryption configuration. KMS name format: 'projects/[PROJECT]/locations/[REGION]/keyRings/[RING]/cryptoKeys/[KEY_NAME]'. | object({…}) | | null | +| [flags](variables.tf#L163) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null | +| [gce_zone](variables.tf#L169) | 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. | string | | null | +| [initial_user](variables.tf#L175) | AlloyDB cluster initial user credentials. | object({…}) | | null | +| [labels](variables.tf#L189) | Labels to be attached to all instances. | map(string) | | null | +| [machine_config](variables.tf#L200) | AlloyDB machine config. | object({…}) | | {…} | +| [maintenance_config](variables.tf#L211) | Set maintenance window configuration. | object({…}) | | {…} | +| [prefix](variables.tf#L284) | Optional prefix used to generate instance names. | string | | null | +| [query_insights_config](variables.tf#L299) | Query insights config. | object({…}) | | {…} | +| [tag_bindings](variables.tf#L315) | Tag bindings for this service, in key => tag value id format. | map(string) | | {} | +| [users](variables.tf#L322) | 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'. | map(object({…})) | | null | ## Outputs diff --git a/modules/alloydb/main.tf b/modules/alloydb/main.tf index 343cd40dc6..6dbf9d6ba8 100644 --- a/modules/alloydb/main.tf +++ b/modules/alloydb/main.tf @@ -20,9 +20,9 @@ locals { # 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'. primary_cluster_name = "${local.prefix}${var.cluster_name}" - primary_instance_name = "${local.prefix}${var.name}" - secondary_cluster_name = coalesce(var.secondary_cluster_name, "${var.cluster_name}-sec") - secondary_instance_name = coalesce(var.secondary_name, "${var.name}-sec") + primary_instance_name = "${local.prefix}${var.instance_name}" + secondary_cluster_name = coalesce(var.cross_region_replication.secondary_cluster_name, "${var.cluster_name}-sec") + secondary_instance_name = coalesce(var.cross_region_replication.secondary_instance_name, "${var.instance_name}-sec") secondary_instance_type = try( var.cross_region_replication.promote_secondary && google_alloydb_cluster.secondary[0].cluster_type == "SECONDARY" ? "SECONDARY" @@ -231,7 +231,7 @@ resource "google_alloydb_cluster" "secondary" { cluster_type = var.cross_region_replication.promote_secondary ? "PRIMARY" : "SECONDARY" database_version = var.database_version deletion_policy = "FORCE" - display_name = coalesce(var.secondary_cluster_display_name, local.secondary_cluster_name) + display_name = coalesce(var.cross_region_replication.secondary_cluster_display_name, local.secondary_cluster_name) labels = var.labels location = var.cross_region_replication.region @@ -353,7 +353,7 @@ 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 = coalesce(var.secondary_display_name, local.secondary_instance_name) + display_name = coalesce(var.cross_region_replication.secondary_instance_name, local.secondary_instance_name) gce_zone = local.is_regional ? null : var.gce_zone instance_id = local.secondary_instance_name instance_type = local.secondary_instance_type diff --git a/modules/alloydb/variables.tf b/modules/alloydb/variables.tf index ad017c0079..11771f00da 100644 --- a/modules/alloydb/variables.tf +++ b/modules/alloydb/variables.tf @@ -117,9 +117,13 @@ variable "continuous_backup_configuration" { variable "cross_region_replication" { description = "Cross region replication config." type = object({ - enabled = optional(bool, false) - promote_secondary = optional(bool, false) - region = optional(string, null) + enabled = optional(bool, false) + promote_secondary = optional(bool, false) + region = optional(string, null) + secondary_cluster_display_name = optional(string, null) + secondary_cluster_name = optional(string, null) + secondary_instance_display_name = optional(string, null) + secondary_instance_name = optional(string, null) }) default = {} validation { @@ -177,6 +181,11 @@ variable "initial_user" { default = null } +variable "instance_name" { + description = "Name of primary instance." + type = string +} + variable "labels" { description = "Labels to be attached to all instances." type = map(string) @@ -239,11 +248,6 @@ variable "maintenance_config" { } } -variable "name" { - description = "Name of primary instance." - type = string -} - variable "network_config" { description = "Network configuration for cluster and instance. Only one between psa_config and psc_config can be used." type = object({ @@ -308,30 +312,6 @@ variable "query_insights_config" { } } -variable "secondary_cluster_display_name" { - description = "Display name of secondary cluster instance." - type = string - default = null -} - -variable "secondary_cluster_name" { - description = "Name of secondary cluster instance." - type = string - default = null -} - -variable "secondary_display_name" { - description = "Display name of secondary instance." - type = string - default = null -} - -variable "secondary_name" { - description = "Name of secondary instance." - type = string - default = null -} - variable "tag_bindings" { description = "Tag bindings for this service, in key => tag value id format." type = map(string)