Skip to content

Commit 49b478a

Browse files
authored
feat: added support for maintenance version (#679)
1 parent 1925f03 commit 49b478a

File tree

14 files changed

+39
-7
lines changed

14 files changed

+39
-7
lines changed

examples/postgresql-with-cross-region-failover/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module "pg1" {
5252
name = var.pg_name_1
5353
random_instance_name = true
5454
project_id = var.project_id
55-
database_version = "POSTGRES_14"
55+
database_version = "POSTGRES_17"
5656
region = local.region_1
5757

5858
edition = local.edition
@@ -158,13 +158,13 @@ module "pg2" {
158158
version = "~> 25.0"
159159

160160

161-
# Comment this parameter to promot instance 2 as primary instance. This will break replication between instance 1 and 2
161+
# Comment this parameter to promote instance 2 as primary instance.
162162
master_instance_name = module.pg1.instance_name
163163

164164
name = var.pg_name_2
165165
random_instance_name = true
166166
project_id = var.project_id
167-
database_version = "POSTGRES_14"
167+
database_version = "POSTGRES_17"
168168
region = local.region_2
169169

170170
edition = local.edition

modules/mssql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module "mssql" {
6161
| 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 |
6262
| instance\_type | 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 when primary\_instance\_name is provided | `string` | `"CLOUD_SQL_INSTANCE"` | no |
6363
| ip\_configuration | The ip configuration for the Cloud SQL instances. | <pre>object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool)<br> private_network = optional(string)<br> allocated_ip_range = optional(string)<br> ssl_mode = optional(string)<br> })</pre> | <pre>{<br> "allocated_ip_range": null,<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "ssl_mode": null<br>}</pre> | no |
64+
| maintenance\_version | The current software version on the instance. This attribute can not be set during creation. Refer to available\_maintenance\_versions attribute to see what maintenance\_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance\_version value that is older than the current one on the instance will be ignored | `string` | `null` | no |
6465
| maintenance\_window\_day | The day of week (1-7) for the Cloud SQL maintenance. | `number` | `1` | no |
6566
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the Cloud SQL maintenance. | `number` | `23` | no |
6667
| maintenance\_window\_update\_track | The update track of maintenance window for the Cloud SQL maintenance.Can be either `canary` or `stable`. | `string` | `"canary"` | no |

modules/mssql/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ resource "google_sql_database_instance" "default" {
4747
project = var.project_id
4848
name = var.random_instance_name ? "${var.name}-${random_id.suffix[0].hex}" : var.name
4949
database_version = var.database_version
50+
maintenance_version = var.maintenance_version
5051
region = var.region
5152
encryption_key_name = var.encryption_key_name
5253
root_password = coalesce(var.root_password, random_password.root-password.result)

modules/mssql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ variable "random_instance_name" {
4242
default = false
4343
}
4444

45+
variable "maintenance_version" {
46+
description = "The current software version on the instance. This attribute can not be set during creation. Refer to available_maintenance_versions attribute to see what maintenance_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance_version value that is older than the current one on the instance will be ignored"
47+
type = string
48+
default = null
49+
}
50+
4551
// required
4652
variable "database_version" {
4753
description = "The database version to use: SQLSERVER_2017_STANDARD, SQLSERVER_2017_ENTERPRISE, SQLSERVER_2017_EXPRESS, or SQLSERVER_2017_WEB"

modules/mysql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module "mysql-db" {
7878
| 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 |
7979
| instance\_type | 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. | `string` | `null` | no |
8080
| ip\_configuration | The ip\_configuration settings subblock | <pre>object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool, true)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> })</pre> | `{}` | no |
81+
| maintenance\_version | The current software version on the instance. This attribute can not be set during creation. Refer to available\_maintenance\_versions attribute to see what maintenance\_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance\_version value that is older than the current one on the instance will be ignored | `string` | `null` | no |
8182
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no |
8283
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no |
8384
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | `string` | `"canary"` | no |

modules/mysql/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ resource "google_sql_database_instance" "default" {
5656
project = var.project_id
5757
name = local.master_instance_name
5858
database_version = var.database_version
59+
maintenance_version = var.maintenance_version
5960
region = var.region
6061
master_instance_name = var.master_instance_name
6162
instance_type = var.instance_type

modules/mysql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ variable "database_version" {
4343
type = string
4444
}
4545

46+
variable "maintenance_version" {
47+
description = "The current software version on the instance. This attribute can not be set during creation. Refer to available_maintenance_versions attribute to see what maintenance_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance_version value that is older than the current one on the instance will be ignored"
48+
type = string
49+
default = null
50+
}
51+
4652
variable "availability_type" {
4753
description = "The availability type for the master instance. Can be either `REGIONAL` or `null`."
4854
type = string

modules/postgresql/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ module "pg" {
127127
| database\_deletion\_policy | The deletion policy for the database. Setting ABANDON allows the resource to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be deleted from the API if there are users other than cloudsqlsuperuser with access. Possible values are: "ABANDON". | `string` | `null` | no |
128128
| database\_flags | The database flags for the Cloud SQL instance. See [more details](https://cloud.google.com/sql/docs/postgres/flags) | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
129129
| database\_integration\_roles | The roles required by default database instance service account for integration with GCP services | `list(string)` | `[]` | no |
130-
| database\_version | The database version to use | `string` | n/a | yes |
130+
| database\_version | The database version to use. Can be 9\_6, 14, 15, 16, 17. | `string` | n/a | yes |
131131
| db\_charset | The charset for the default database | `string` | `""` | no |
132132
| db\_collation | The collation for the default database. Example: 'en\_US.UTF8' | `string` | `""` | no |
133133
| db\_name | The name of the default database to create. This should be unique per Cloud SQL instance. | `string` | `"default"` | no |
@@ -150,6 +150,7 @@ module "pg" {
150150
| 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 |
151151
| instance\_type | 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 | `string` | `"CLOUD_SQL_INSTANCE"` | no |
152152
| ip\_configuration | The ip configuration for the Cloud SQL instances. | <pre>object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool, true)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> })</pre> | `{}` | no |
153+
| maintenance\_version | The current software version on the instance. This attribute can not be set during creation. Refer to available\_maintenance\_versions attribute to see what maintenance\_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance\_version value that is older than the current one on the instance will be ignored | `string` | `null` | no |
153154
| maintenance\_window\_day | The day of week (1-7) for the Cloud SQL instance maintenance. | `number` | `1` | no |
154155
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the Cloud SQL instance maintenance. | `number` | `23` | no |
155156
| maintenance\_window\_update\_track | The update track of maintenance window for the Cloud SQL instance maintenance.Can be either `canary` or `stable`. | `string` | `"canary"` | no |

modules/postgresql/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ resource "google_sql_database_instance" "default" {
5858
project = var.project_id
5959
name = local.instance_name
6060
database_version = can(regex("\\d", substr(var.database_version, 0, 1))) ? format("POSTGRES_%s", var.database_version) : replace(var.database_version, substr(var.database_version, 0, 8), "POSTGRES")
61+
maintenance_version = var.maintenance_version
6162
region = var.region
6263
encryption_key_name = var.encryption_key_name
6364
deletion_protection = var.deletion_protection

modules/postgresql/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,21 @@ variable "edition" {
3838

3939
// required
4040
variable "database_version" {
41-
description = "The database version to use"
41+
description = "The database version to use. Can be 9_6, 14, 15, 16, 17."
4242
type = string
4343

4444
validation {
4545
condition = (length(var.database_version) >= 9 && ((upper(substr(var.database_version, 0, 9)) == "POSTGRES_") && can(regex("^\\d+(?:_?\\d)*$", substr(var.database_version, 9, -1))))) || can(regex("^\\d+(?:_?\\d)*$", var.database_version))
46-
error_message = "The specified database version is not a valid representaion of database version. Valid database versions should be like the following patterns:- \"9_6\", \"postgres_9_6\", \"POSTGRES_14\" or \"POSTGRES_15\""
46+
error_message = "The specified database version is not a valid representation of database version. Valid database versions should be like the following patterns:- \"9_6\", \"postgres_9_6\", \"14\", \"POSTGRES_14\", \"15\", \"POSTGRES_15\", \"16\", \"POSTGRES_16\" or \"17\", \"POSTGRES_17\""
4747
}
4848
}
4949

50+
variable "maintenance_version" {
51+
description = "The current software version on the instance. This attribute can not be set during creation. Refer to available_maintenance_versions attribute to see what maintenance_version are available for upgrade. When this attribute gets updated, it will cause an instance restart. Setting a maintenance_version value that is older than the current one on the instance will be ignored"
52+
type = string
53+
default = null
54+
}
55+
5056
variable "availability_type" {
5157
description = "The availability type for the Cloud SQL instance.This is only used to set up high availability for the PostgreSQL instance. Can be either `ZONAL` or `REGIONAL`."
5258
type = string

0 commit comments

Comments
 (0)