diff --git a/modules/alloydb/README.md b/modules/alloydb/README.md
index 8f7679867..35f2390ac 100644
--- a/modules/alloydb/README.md
+++ b/modules/alloydb/README.md
@@ -343,37 +343,37 @@ module "alloydb" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
-| [cluster_name](variables.tf#L81) | Name of the primary cluster. | string | ✓ | |
-| [instance_name](variables.tf#L208) | Name of primary instance. | string | ✓ | |
-| [location](variables.tf#L220) | Region or zone of the cluster and instance. | string | ✓ | |
-| [network_config](variables.tf#L265) | Network configuration for cluster and instance. Only one between psa_config and psc_config can be used. | object({…}) | ✓ | |
-| [project_id](variables.tf#L300) | The ID of the project where this instances will be created. | string | ✓ | |
+| [cluster_name](variables.tf#L84) | Name of the primary cluster. | string | ✓ | |
+| [instance_name](variables.tf#L211) | Name of primary instance. | string | ✓ | |
+| [location](variables.tf#L223) | Region or zone of the cluster and instance. | string | ✓ | |
+| [network_config](variables.tf#L268) | Network configuration for cluster and instance. Only one between psa_config and psc_config can be used. | object({…}) | ✓ | |
+| [project_id](variables.tf#L303) | 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#L58) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | string | | "REGIONAL" |
-| [client_connection_config](variables.tf#L64) | Client connection config. | object({…}) | | null |
-| [cluster_display_name](variables.tf#L75) | Display name of the primary cluster. | string | | null |
-| [continuous_backup_configuration](variables.tf#L87) | Continuous backup settings for cluster. | object({…}) | | {} |
-| [cross_region_replication](variables.tf#L97) | Cross region replication config. | object({…}) | | {} |
-| [database_version](variables.tf#L154) | Database type and version to create. | string | | "POSTGRES_15" |
-| [deletion_policy](variables.tf#L160) | AlloyDB cluster and instance deletion policy. | string | | null |
-| [deletion_protection](variables.tf#L166) | Whether Terraform will be prevented from destroying the cluster. When the field is set to true or unset in Terraform state, a terraform apply or terraform destroy that would delete the cluster will fail. When the field is set to false, deleting the cluster is allowed. | bool | | null |
-| [display_name](variables.tf#L172) | AlloyDB instance display name. | string | | null |
-| [encryption_config](variables.tf#L178) | Set encryption configuration. KMS name format: 'projects/[PROJECT]/locations/[REGION]/keyRings/[RING]/cryptoKeys/[KEY_NAME]'. | object({…}) | | null |
-| [flags](variables.tf#L187) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null |
-| [gce_zone](variables.tf#L193) | 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#L199) | AlloyDB cluster initial user credentials. | object({…}) | | null |
-| [labels](variables.tf#L214) | Labels to be attached to all instances. | map(string) | | null |
-| [machine_config](variables.tf#L226) | AlloyDB machine config. | object({…}) | | {} |
-| [maintenance_config](variables.tf#L240) | Set maintenance window configuration. | object({…}) | | {} |
-| [prefix](variables.tf#L290) | Optional prefix used to generate instance names. | string | | null |
-| [project_number](variables.tf#L305) | The project number of the project where this instances will be created. Only used for testing purposes. | string | | null |
-| [query_insights_config](variables.tf#L311) | Query insights config. | object({…}) | | {} |
-| [read_pool](variables.tf#L322) | Map of read pool instances to create in the primary cluster. | map(object({…})) | | {} |
-| [skip_await_major_version_upgrade](variables.tf#L367) | Set to true to skip awaiting on the major version upgrade of the cluster. | bool | | true |
-| [subscription_type](variables.tf#L373) | The subscription type of cluster. Possible values are: 'STANDARD' or 'TRIAL'. | string | | "STANDARD" |
-| [tag_bindings](variables.tf#L379) | Tag bindings for this service, in key => tag value id format. | map(string) | | {} |
-| [users](variables.tf#L386) | 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({…})) | | {} |
+| [automated_backup_configuration](variables.tf#L23) | Automated backup settings for cluster. | object({…}) | | {} |
+| [availability_type](variables.tf#L61) | Availability type for the primary replica. Either `ZONAL` or `REGIONAL`. | string | | "REGIONAL" |
+| [client_connection_config](variables.tf#L67) | Client connection config. | object({…}) | | null |
+| [cluster_display_name](variables.tf#L78) | Display name of the primary cluster. | string | | null |
+| [continuous_backup_configuration](variables.tf#L90) | Continuous backup settings for cluster. | object({…}) | | {} |
+| [cross_region_replication](variables.tf#L100) | Cross region replication config. | object({…}) | | {} |
+| [database_version](variables.tf#L157) | Database type and version to create. | string | | "POSTGRES_15" |
+| [deletion_policy](variables.tf#L163) | AlloyDB cluster and instance deletion policy. | string | | null |
+| [deletion_protection](variables.tf#L169) | Whether Terraform will be prevented from destroying the cluster. When the field is set to true or unset in Terraform state, a terraform apply or terraform destroy that would delete the cluster will fail. When the field is set to false, deleting the cluster is allowed. | bool | | null |
+| [display_name](variables.tf#L175) | AlloyDB instance display name. | string | | null |
+| [encryption_config](variables.tf#L181) | Set encryption configuration. KMS name format: 'projects/[PROJECT]/locations/[REGION]/keyRings/[RING]/cryptoKeys/[KEY_NAME]'. | object({…}) | | null |
+| [flags](variables.tf#L190) | Map FLAG_NAME=>VALUE for database-specific tuning. | map(string) | | null |
+| [gce_zone](variables.tf#L196) | 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#L202) | AlloyDB cluster initial user credentials. | object({…}) | | null |
+| [labels](variables.tf#L217) | Labels to be attached to all instances. | map(string) | | null |
+| [machine_config](variables.tf#L229) | AlloyDB machine config. | object({…}) | | {} |
+| [maintenance_config](variables.tf#L243) | Set maintenance window configuration. | object({…}) | | {} |
+| [prefix](variables.tf#L293) | Optional prefix used to generate instance names. | string | | null |
+| [project_number](variables.tf#L308) | The project number of the project where this instances will be created. Only used for testing purposes. | string | | null |
+| [query_insights_config](variables.tf#L314) | Query insights config. | object({…}) | | {} |
+| [read_pool](variables.tf#L325) | Map of read pool instances to create in the primary cluster. | map(object({…})) | | {} |
+| [skip_await_major_version_upgrade](variables.tf#L370) | Set to true to skip awaiting on the major version upgrade of the cluster. | bool | | true |
+| [subscription_type](variables.tf#L376) | The subscription type of cluster. Possible values are: 'STANDARD' or 'TRIAL'. | string | | "STANDARD" |
+| [tag_bindings](variables.tf#L382) | Tag bindings for this service, in key => tag value id format. | map(string) | | {} |
+| [users](variables.tf#L389) | 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({…})) | | {} |
## Outputs
diff --git a/modules/alloydb/main.tf b/modules/alloydb/main.tf
index 4b623e261..6569c4e81 100644
--- a/modules/alloydb/main.tf
+++ b/modules/alloydb/main.tf
@@ -102,11 +102,14 @@ resource "google_alloydb_cluster" "primary" {
weekly_schedule {
days_of_week = var.automated_backup_configuration.weekly_schedule.days_of_week
- start_times {
- hours = var.automated_backup_configuration.weekly_schedule.start_times.hours
- minutes = 0
- seconds = 0
- nanos = 0
+ dynamic "start_times" {
+ for_each = var.automated_backup_configuration.weekly_schedule.start_times
+ content {
+ hours = start_times.value.hours
+ minutes = 0
+ seconds = 0
+ nanos = 0
+ }
}
}
diff --git a/modules/alloydb/variables.tf b/modules/alloydb/variables.tf
index 9df621486..c9314a9ca 100644
--- a/modules/alloydb/variables.tf
+++ b/modules/alloydb/variables.tf
@@ -30,9 +30,9 @@ variable "automated_backup_configuration" {
days_of_week = optional(list(string), [
"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"
])
- start_times = optional(object({
- hours = optional(number, 23)
- }), {})
+ start_times = optional(list(object({
+ hours = number
+ })), [{ hours = 23 }])
}), {})
retention_count = optional(number, 7)
retention_period = optional(string)
@@ -45,8 +45,11 @@ variable "automated_backup_configuration" {
# Backup window validation below
!(var.automated_backup_configuration.retention_count != null && var.automated_backup_configuration.retention_period != null) &&
# Backup window hours below
- var.automated_backup_configuration.weekly_schedule.start_times.hours >= 0 &&
- var.automated_backup_configuration.weekly_schedule.start_times.hours <= 23 &&
+ (alltrue([
+ for v in var.automated_backup_configuration.weekly_schedule.start_times :
+ v.hours >= 0 &&
+ v.hours <= 23
+ ])) &&
# Backup window day validation
setintersection(["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"], var.automated_backup_configuration.weekly_schedule.days_of_week) == toset(var.automated_backup_configuration.weekly_schedule.days_of_week)
) : true