Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for maintenance version #679

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions examples/postgresql-with-cross-region-failover/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module "pg1" {
name = var.pg_name_1
random_instance_name = true
project_id = var.project_id
database_version = "POSTGRES_14"
database_version = "POSTGRES_17"
region = local.region_1

edition = local.edition
Expand Down Expand Up @@ -164,7 +164,7 @@ module "pg2" {
name = var.pg_name_2
random_instance_name = true
project_id = var.project_id
database_version = "POSTGRES_14"
database_version = "POSTGRES_17"
region = local.region_2

edition = local.edition
Expand Down
1 change: 1 addition & 0 deletions modules/mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module "mssql" {
| 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 |
| 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 |
| 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 |
| 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 |
| maintenance\_window\_day | The day of week (1-7) for the Cloud SQL maintenance. | `number` | `1` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the Cloud SQL maintenance. | `number` | `23` | no |
| maintenance\_window\_update\_track | The update track of maintenance window for the Cloud SQL maintenance.Can be either `canary` or `stable`. | `string` | `"canary"` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/mssql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ resource "google_sql_database_instance" "default" {
project = var.project_id
name = var.random_instance_name ? "${var.name}-${random_id.suffix[0].hex}" : var.name
database_version = var.database_version
maintenance_version = var.maintenance_version
region = var.region
encryption_key_name = var.encryption_key_name
root_password = coalesce(var.root_password, random_password.root-password.result)
Expand Down
6 changes: 6 additions & 0 deletions modules/mssql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ variable "random_instance_name" {
default = false
}

variable "maintenance_version" {
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"
type = string
default = null
}

// required
variable "database_version" {
description = "The database version to use: SQLSERVER_2017_STANDARD, SQLSERVER_2017_ENTERPRISE, SQLSERVER_2017_EXPRESS, or SQLSERVER_2017_WEB"
Expand Down
1 change: 1 addition & 0 deletions modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module "mysql-db" {
| 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 |
| 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 |
| 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 |
| 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 |
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no |
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | `string` | `"canary"` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ resource "google_sql_database_instance" "default" {
project = var.project_id
name = local.master_instance_name
database_version = var.database_version
maintenance_version = var.maintenance_version
region = var.region
master_instance_name = var.master_instance_name
instance_type = var.instance_type
Expand Down
6 changes: 6 additions & 0 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ variable "database_version" {
type = string
}

variable "maintenance_version" {
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"
type = string
default = null
}

variable "availability_type" {
description = "The availability type for the master instance. Can be either `REGIONAL` or `null`."
type = string
Expand Down
3 changes: 2 additions & 1 deletion modules/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module "pg" {
| 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 |
| 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 |
| database\_integration\_roles | The roles required by default database instance service account for integration with GCP services | `list(string)` | `[]` | no |
| database\_version | The database version to use | `string` | n/a | yes |
| database\_version | The database version to use. Can be 9\_6, 14, 15, 16, 17. | `string` | n/a | yes |
| db\_charset | The charset for the default database | `string` | `""` | no |
| db\_collation | The collation for the default database. Example: 'en\_US.UTF8' | `string` | `""` | no |
| db\_name | The name of the default database to create | `string` | `"default"` | no |
Expand All @@ -150,6 +150,7 @@ module "pg" {
| 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 |
| 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 |
| 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 |
| 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 |
| maintenance\_window\_day | The day of week (1-7) for the Cloud SQL instance maintenance. | `number` | `1` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the Cloud SQL instance maintenance. | `number` | `23` | no |
| 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 |
Expand Down
1 change: 1 addition & 0 deletions modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resource "google_sql_database_instance" "default" {
project = var.project_id
name = local.instance_name
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")
maintenance_version = var.maintenance_version
region = var.region
encryption_key_name = var.encryption_key_name
deletion_protection = var.deletion_protection
Expand Down
10 changes: 8 additions & 2 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ variable "edition" {

// required
variable "database_version" {
description = "The database version to use"
description = "The database version to use. Can be 9_6, 14, 15, 16, 17."
type = string

validation {
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))
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\""
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\""
}
}

variable "maintenance_version" {
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"
type = string
default = null
}

variable "availability_type" {
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`."
type = string
Expand Down
1 change: 1 addition & 0 deletions modules/safer_mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ module "safer-mysql-db" {
| 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 |
| 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 |
| 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 |
| 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 |
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | `number` | `1` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | `number` | `23` | no |
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | `string` | `"stable"` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/safer_mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module "safer_mysql" {
name = var.name
random_instance_name = var.random_instance_name
database_version = var.database_version
maintenance_version = var.maintenance_version
region = var.region
zone = var.zone
secondary_zone = var.secondary_zone
Expand Down
6 changes: 6 additions & 0 deletions modules/safer_mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ variable "database_version" {
type = string
}

variable "maintenance_version" {
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"
type = string
default = null
}

// required
variable "region" {
description = "The region of the Cloud SQL resources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestPostgreSqlCrossRegionFailover(t *testing.T) {
assert.Equal(1, len(authNetworks), "Expected one auth network")

/// assert standard database settings
assert.Equal("POSTGRES_14", op.Get("databaseVersion").String(), "Expected POSTGRES_14 databaseVersion")
assert.Equal("POSTGRES_17", op.Get("databaseVersion").String(), "Expected POSTGRES_17 databaseVersion")
assert.Equal("SECOND_GEN", op.Get("backendType").String(), "Expected SECOND_GEN backendType")
assert.Equal("RUNNABLE", op.Get("state").String(), "Expected RUNNABLE state")
assert.Equal("us-central1", op.Get("region").String(), "Expected us-central1 region")
Expand Down
Loading