Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google_cloudsql_mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module "mysql_database" {
| <a name="input_component"></a> [component](#input\_component) | A logical component of an application | `string` | `"db"` | no |
| <a name="input_connector_enforcement"></a> [connector\_enforcement](#input\_connector\_enforcement) | Enables the enforcement of Cloud SQL Auth Proxy or Cloud SQL connectors for all the connections. If enabled, all the direct connections are rejected. | `string` | `null` | no |
| <a name="input_custom_database_name"></a> [custom\_database\_name](#input\_custom\_database\_name) | Use this field for custom database name. | `string` | `""` | no |
| <a name="input_custom_replica_name"></a> [custom\_replica\_name](#input\_custom\_replica\_name) | Custom database replica name. | `string` | `""` | no |
| <a name="input_custom_replica_name"></a> [custom\_replica\_name](#input\_custom\_replica\_name) | Custom database replica name. | `list(string)` | `[]` | no |
| <a name="input_data_cache_enabled"></a> [data\_cache\_enabled](#input\_data\_cache\_enabled) | Whether data cache is enabled for the instance. Only available for `ENTERPRISE_PLUS` edition instances. | `bool` | `true` | no |
| <a name="input_database_flags"></a> [database\_flags](#input\_database\_flags) | The database flags for the primary instance. See [more details](https://cloud.google.com/sql/docs/mysql/flags#list-flags-mysql) | `list(object({ name = string, value = string }))` | `[]` | no |
| <a name="input_database_version"></a> [database\_version](#input\_database\_version) | Version of MySQL to run | `string` | `"MYSQL_8_0"` | no |
Expand Down
4 changes: 2 additions & 2 deletions google_cloudsql_mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ locals {
replica_availability_type = coalesce(var.replica_availability_type_override, var.availability_type)

default_replica_name = "${local.database_name}-replica"
replica_name = coalesce(var.custom_replica_name, local.default_replica_name)
replica_names = coalescelist(var.custom_replica_name, [for index in range(var.replica_count) : "${local.default_replica_name}-${index}"])

ip_addresses = google_sql_database_instance.primary.ip_address

Expand Down Expand Up @@ -129,7 +129,7 @@ resource "google_sql_database_instance" "primary" {

resource "google_sql_database_instance" "replica" {
count = var.replica_count
name = "${local.replica_name}-${count.index}"
name = local.replica_names[count.index]
project = var.project_id
region = local.replica_region
database_version = var.database_version
Expand Down
9 changes: 7 additions & 2 deletions google_cloudsql_mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ variable "custom_database_name" {
}

variable "custom_replica_name" {
default = ""
default = []
description = "Custom database replica name."
type = string
type = list(string)

validation {
condition = length(var.custom_replica_name) == 0 || length(var.custom_replica_name) == var.replica_count
error_message = "Replicas must use default replica name or define a replica name for every replica."
}
}

variable "data_cache_enabled" {
Expand Down
Loading