Skip to content

Commit 90a3e64

Browse files
authored
feat(TPG>6.17)!: Adding new variables to define failover dr replica (#728)
1 parent af7f20c commit 90a3e64

File tree

16 files changed

+81
-5
lines changed

16 files changed

+81
-5
lines changed

docs/upgrading_to_sql_db_26.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Upgrading to v26.0
2+
3+
The v26.0 release contains backwards-incompatible changes.
4+
5+
This update requires upgrading the minimum provider version from `6.1` to `6.17`

modules/mysql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module "mysql-db" {
7474
| enable\_google\_ml\_integration | Enable database ML integration | `bool` | `false` | no |
7575
| enable\_random\_password\_special | Enable special characters in generated random passwords. | `bool` | `false` | no |
7676
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |
77+
| failover\_dr\_replica\_name | If the instance is a primary instance, then this field identifies the disaster recovery (DR) replica. The standard format of this field is "your-project:your-instance". You can also set this field to "your-instance", but cloud SQL backend will convert it to the aforementioned standard format. | `string` | `null` | no |
7778
| follow\_gae\_application | A Google App Engine application whose zone to remain in. Must be in the same region as this instance. | `string` | `null` | no |
7879
| iam\_users | A list of IAM users to be created in your CloudSQL instance. iam.users.type can be CLOUD\_IAM\_USER, CLOUD\_IAM\_SERVICE\_ACCOUNT, CLOUD\_IAM\_GROUP and is required for type CLOUD\_IAM\_GROUP (IAM groups) | <pre>list(object({<br> id = string,<br> email = string,<br> type = optional(string)<br> }))</pre> | `[]` | no |
7980
| insights\_config | The insights\_config settings for the database. | <pre>object({<br> query_plans_per_minute = number<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> })</pre> | `null` | no |

modules/mysql/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ resource "google_sql_database_instance" "default" {
6464
deletion_protection = var.deletion_protection
6565
root_password = var.root_password == "" ? null : var.root_password
6666

67+
dynamic "replication_cluster" {
68+
for_each = var.failover_dr_replica_name != null ? [var.failover_dr_replica_name] : []
69+
content {
70+
failover_dr_replica_name = var.failover_dr_replica_name
71+
}
72+
}
73+
6774
settings {
6875
tier = var.tier
6976
edition = var.edition

modules/mysql/metadata.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ spec:
182182
- name: master_instance_name
183183
description: The name of the existing instance that will act as the master in the replication setup.
184184
varType: string
185+
- name: failover_dr_replica_name
186+
description: If the instance is a primary instance, then this field identifies the disaster recovery (DR) replica. The standard format of this field is "your-project:your-instance". You can also set this field to "your-instance", but cloud SQL backend will convert it to the aforementioned standard format.
187+
varType: string
185188
- name: instance_type
186189
description: Users can upgrade a read replica instance to a stand-alone Cloud SQL instance with the help of instance_type. To promote, users have to set the instance_type property as CLOUD_SQL_INSTANCE and remove/unset master_instance_name and replica_configuration from instance configuration. This operation might cause your instance to restart.
187190
varType: string

modules/mysql/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ variable "master_instance_name" {
169169
default = null
170170
}
171171

172+
//optional
173+
variable "failover_dr_replica_name" {
174+
type = string
175+
description = "If the instance is a primary instance, then this field identifies the disaster recovery (DR) replica. The standard format of this field is \"your-project:your-instance\". You can also set this field to \"your-instance\", but cloud SQL backend will convert it to the aforementioned standard format."
176+
default = null
177+
}
178+
172179
// optional
173180
variable "instance_type" {
174181
description = "Users can upgrade a read replica instance to a stand-alone Cloud SQL instance with the help of instance_type. To promote, users have to set the instance_type property as CLOUD_SQL_INSTANCE and remove/unset master_instance_name and replica_configuration from instance configuration. This operation might cause your instance to restart."

modules/mysql/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ terraform {
2727
}
2828
google = {
2929
source = "hashicorp/google"
30-
version = ">= 6.1, < 7"
30+
version = ">= 6.17, < 7"
3131
}
3232
google-beta = {
3333
source = "hashicorp/google-beta"
34-
version = ">= 6.1, < 7"
34+
version = ">= 6.17, < 7"
3535
}
3636
}
3737

modules/postgresql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ module "pg" {
146146
| enable\_google\_ml\_integration | Enable database ML integration | `bool` | `false` | no |
147147
| enable\_random\_password\_special | Enable special characters in generated random passwords. | `bool` | `false` | no |
148148
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |
149+
| failover\_dr\_replica\_name | If the instance is a primary instance, then this field identifies the disaster recovery (DR) replica. The standard format of this field is "your-project:your-instance". You can also set this field to "your-instance", but cloud SQL backend will convert it to the aforementioned standard format. | `string` | `null` | no |
149150
| follow\_gae\_application | A Google App Engine application whose zone to remain in. Must be in the same region as this instance. | `string` | `null` | no |
150151
| iam\_users | A list of IAM users to be created in your CloudSQL instance. iam.users.type can be CLOUD\_IAM\_USER, CLOUD\_IAM\_SERVICE\_ACCOUNT, CLOUD\_IAM\_GROUP and is required for type CLOUD\_IAM\_GROUP (IAM groups) | <pre>list(object({<br> id = string,<br> email = string,<br> type = optional(string)<br> }))</pre> | `[]` | no |
151152
| insights\_config | The insights\_config settings for the database. | <pre>object({<br> query_plans_per_minute = optional(number, 5)<br> query_string_length = optional(number, 1024)<br> record_application_tags = optional(bool, false)<br> record_client_address = optional(bool, false)<br> })</pre> | `null` | no |

modules/postgresql/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ resource "google_sql_database_instance" "default" {
6969
master_instance_name = var.master_instance_name
7070
instance_type = local.is_secondary_instance ? "READ_REPLICA_INSTANCE" : var.instance_type
7171

72+
dynamic "replication_cluster" {
73+
for_each = var.failover_dr_replica_name != null ? [var.failover_dr_replica_name] : []
74+
content {
75+
failover_dr_replica_name = var.failover_dr_replica_name
76+
}
77+
}
78+
7279
settings {
7380
tier = var.tier
7481
edition = var.edition

modules/postgresql/metadata.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ spec:
154154
- name: master_instance_name
155155
description: Name of the master instance if this is a failover replica. Required for creating failover replica instance. Not needed for master instance. When removed, next terraform apply will promote this failover failover replica instance as master instance
156156
varType: string
157+
- name: failover_dr_replica_name
158+
description: If the instance is a primary instance, then this field identifies the disaster recovery (DR) replica. The standard format of this field is "your-project:your-instance". You can also set this field to "your-instance", but cloud SQL backend will convert it to the aforementioned standard format.
159+
varType: string
157160
- name: instance_type
158161
description: The type of the instance. The supported values are SQL_INSTANCE_TYPE_UNSPECIFIED, CLOUD_SQL_INSTANCE, ON_PREMISES_INSTANCE and READ_REPLICA_INSTANCE. Set to READ_REPLICA_INSTANCE if master_instance_name value is provided
159162
varType: string

modules/postgresql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ variable "master_instance_name" {
158158
default = null
159159
}
160160

161+
variable "failover_dr_replica_name" {
162+
type = string
163+
description = "If the instance is a primary instance, then this field identifies the disaster recovery (DR) replica. The standard format of this field is \"your-project:your-instance\". You can also set this field to \"your-instance\", but cloud SQL backend will convert it to the aforementioned standard format."
164+
default = null
165+
}
166+
161167
variable "instance_type" {
162168
type = string
163169
description = "The type of the instance. The supported values are SQL_INSTANCE_TYPE_UNSPECIFIED, CLOUD_SQL_INSTANCE, ON_PREMISES_INSTANCE and READ_REPLICA_INSTANCE. Set to READ_REPLICA_INSTANCE if master_instance_name value is provided"

0 commit comments

Comments
 (0)