alloydb variables refactor (#2599)
This commit is contained in:
committed by
GitHub
parent
cb234fd35b
commit
77b8f639ed
@@ -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. | <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 psa_config and psc_config can be used. | <code title="object({ psa_config = optional(object({ network = optional(string) allocated_ip_range = optional(string) authorized_external_networks = optional(list(string), []) enable_public_ip = optional(bool, false) })) psc_config = optional(object({ allowed_consumer_projects = optional(list(string), []) }), null) })">object({…})</code> | ✓ | |
|
||||
| [project_id](variables.tf#L290) | The ID of the project where this instances will be created. | <code>string</code> | ✓ | |
|
||||
| [instance_name](variables.tf#L184) | Name of primary instance. | <code>string</code> | ✓ | |
|
||||
| [location](variables.tf#L195) | Region or zone of the cluster and instance. | <code>string</code> | ✓ | |
|
||||
| [network_config](variables.tf#L251) | Network configuration for cluster and instance. Only one between psa_config and psc_config can be used. | <code title="object({ psa_config = optional(object({ network = optional(string) allocated_ip_range = optional(string) authorized_external_networks = optional(list(string), []) enable_public_ip = optional(bool, false) })) psc_config = optional(object({ allowed_consumer_projects = optional(list(string), []) }), null) })">object({…})</code> | ✓ | |
|
||||
| [project_id](variables.tf#L294) | 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#L280) | Optional prefix used to generate instance names. | <code>string</code> | | <code>null</code> |
|
||||
| [query_insights_config](variables.tf#L295) | 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#L311) | Display name of secondary cluster instance. | <code>string</code> | | <code>null</code> |
|
||||
| [secondary_cluster_name](variables.tf#L317) | Name of secondary cluster instance. | <code>string</code> | | <code>null</code> |
|
||||
| [secondary_display_name](variables.tf#L323) | Display name of secondary instance. | <code>string</code> | | <code>null</code> |
|
||||
| [secondary_name](variables.tf#L329) | Name of secondary instance. | <code>string</code> | | <code>null</code> |
|
||||
| [tag_bindings](variables.tf#L335) | Tag bindings for this service, in key => tag value id format. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [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'. | <code title="map(object({ password = optional(string) roles = optional(list(string), ["alloydbsuperuser"]) type = optional(string) }))">map(object({…}))</code> | | <code>null</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) 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) })">object({…})</code> | | <code>{}</code> |
|
||||
| [database_version](variables.tf#L135) | Database type and version to create. | <code>string</code> | | <code>"POSTGRES_15"</code> |
|
||||
| [deletion_policy](variables.tf#L141) | AlloyDB cluster and instance deletion policy. | <code>string</code> | | <code>null</code> |
|
||||
| [display_name](variables.tf#L147) | AlloyDB instance display name. | <code>string</code> | | <code>null</code> |
|
||||
| [encryption_config](variables.tf#L153) | 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#L163) | Map FLAG_NAME=>VALUE for database-specific tuning. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [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. | <code>string</code> | | <code>null</code> |
|
||||
| [initial_user](variables.tf#L175) | AlloyDB cluster initial user credentials. | <code title="object({ user = optional(string, "root") password = string })">object({…})</code> | | <code>null</code> |
|
||||
| [labels](variables.tf#L189) | Labels to be attached to all instances. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [machine_config](variables.tf#L200) | AlloyDB machine config. | <code title="object({ cpu_count = optional(number, 2) })">object({…})</code> | | <code title="{ cpu_count = 2 }">{…}</code> |
|
||||
| [maintenance_config](variables.tf#L211) | 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#L284) | Optional prefix used to generate instance names. | <code>string</code> | | <code>null</code> |
|
||||
| [query_insights_config](variables.tf#L299) | 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> |
|
||||
| [tag_bindings](variables.tf#L315) | Tag bindings for this service, in key => tag value id format. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [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'. | <code title="map(object({ password = optional(string) roles = optional(list(string), ["alloydbsuperuser"]) type = optional(string) }))">map(object({…}))</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user