Skip to content

Commit

Permalink
feat!: Add support for setting disk_autoresize_limit (#288)
Browse files Browse the repository at this point in the history
* feat: Add support for setting disk_autoresize_limit

* Fix indentation for read_replicas in docs

* Run make generate_docs

* Added disk_autoresize_limit to read_replicas variable

* Added upgrading to 11.0 guide

* Update docs/upgrading_to_sql_db_11.0.0.md

Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>

Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>
  • Loading branch information
kostiantyn-nemchenko and bharathkkb committed May 26, 2022
1 parent 449f1a2 commit e07f141
Show file tree
Hide file tree
Showing 23 changed files with 246 additions and 108 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The current version is 3.X. The following guides are available to assist with up

- [1.X -> 2.0](./docs/upgrading_to_sql_db_2.0.0.md)
- [2.X -> 3.0](./docs/upgrading_to_sql_db_3.0.0.md)
- [3.X -> 4.0](./docs/upgrading_to_sql_db_4.0.0.md)
- [10.X -> 11.0](./docs/upgrading_to_sql_db_11.0.0.md)

## Root module

Expand Down
93 changes: 93 additions & 0 deletions docs/upgrading_to_sql_db_11.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Upgrading to SQL DB 11.0.0

The 11.0.0 release of SQL DB is a backward incompatible release. This incompatibility affects configuration of read replicas for `mysql`, `postgresql` and `safer_mysql` submodules.

## Migration Instructions

Prior to the 11.0.0 release, all instances could only be created without a limit.

```hcl
module "pg" {
source = "GoogleCloudPlatform/sql-db/google//modules/postgresql"
version = "~> 10.0"
project_id = var.project_id
region = "europe-west1"
zone = "europe-west1-d"
name = "test"
random_instance_name = true
availability_type = "ZONAL"
database_version = "POSTGRES_14"
disk_type = "PD_HDD"
disk_size = 10
disk_autoresize = true
create_timeout = "30m"
read_replicas = [
{
name = "0"
zone = "europe-west1-d"
tier = "db-f1-micro"
disk_type = "PD_HDD"
disk_size = 10
disk_autoresize = true
encryption_key_name = null
database_flags = []
user_labels = {}
ip_configuration = {
allocated_ip_range = null
authorized_networks = []
ipv4_enabled = true
private_network = null
require_ssl = false
}
},
]
}
```

With the 11.0.0 release, the `disk_autoresize_limit` number variable is presented which allows users to set a specific limit on how large the storage on their instance can automatically grow. The default value is zero, which means there is no limit and disk size can grow up to the maximum available storage for the instance tier. Applying the automatic disk increase limit does not cause any disruptions to your database workload.

```diff
module "pg" {
source = "GoogleCloudPlatform/sql-db/google//modules/postgresql"
- version = "~> 10.0"
+ version = "~> 11.0"

project_id = var.project_id
region = "europe-west1"
zone = "europe-west1-d"
name = "test"
random_instance_name = true
availability_type = "ZONAL"
database_version = "POSTGRES_14"
disk_type = "PD_HDD"
disk_size = 10
disk_autoresize = true
create_timeout = "30m"

read_replicas = [
{
name = "0"
zone = "europe-west1-d"
tier = "db-f1-micro"
disk_type = "PD_HDD"
disk_size = 10
disk_autoresize = true
+ disk_autoresize_limit = 0
encryption_key_name = null
database_flags = []
user_labels = {}

ip_configuration = {
allocated_ip_range = null
authorized_networks = []
ipv4_enabled = true
private_network = null
require_ssl = false
}
},
]
}
```
63 changes: 33 additions & 30 deletions examples/mysql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,43 @@ module "mysql" {
read_replica_name_suffix = "-test"
read_replicas = [
{
name = "0"
zone = "us-central1-a"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
name = "0"
zone = "us-central1-a"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_autoresize_limit = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
},
{
name = "1"
zone = "us-central1-b"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
name = "1"
zone = "us-central1-b"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_autoresize_limit = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
},
{
name = "2"
zone = "us-central1-c"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
name = "2"
zone = "us-central1-c"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_autoresize_limit = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
},
]

Expand Down
63 changes: 33 additions & 30 deletions examples/postgresql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,43 @@ module "pg" {
read_replica_name_suffix = "-test"
read_replicas = [
{
name = "0"
zone = "us-central1-a"
tier = "db-custom-1-3840"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
name = "0"
zone = "us-central1-a"
tier = "db-custom-1-3840"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_autoresize_limit = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
},
{
name = "1"
zone = "us-central1-b"
tier = "db-custom-1-3840"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
name = "1"
zone = "us-central1-b"
tier = "db-custom-1-3840"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_autoresize_limit = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
},
{
name = "2"
zone = "us-central1-c"
tier = "db-custom-1-3840"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
name = "2"
zone = "us-central1-c"
tier = "db-custom-1-3840"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_autoresize_limit = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
encryption_key_name = null
},
]

Expand Down
1 change: 1 addition & 0 deletions modules/mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following dependency must be available for SQL Server module:
| delete\_timeout | The optional timeout that is applied to limit long database deletes. | `string` | `"30m"` | no |
| deletion\_protection | Used to block Terraform from deleting a SQL Instance. | `bool` | `true` | no |
| disk\_autoresize | Configuration to increase storage size. | `bool` | `true` | no |
| disk\_autoresize\_limit | The maximum size to which storage can be auto increased. | `number` | `0` | no |
| disk\_size | The disk size for the master instance. | `number` | `10` | no |
| disk\_type | The disk type for the master instance. | `string` | `"PD_SSD"` | no |
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |
Expand Down
9 changes: 5 additions & 4 deletions modules/mssql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ resource "google_sql_database_instance" "default" {
}
}

disk_autoresize = var.disk_autoresize
disk_size = var.disk_size
disk_type = var.disk_type
pricing_plan = var.pricing_plan
disk_autoresize = var.disk_autoresize
disk_autoresize_limit = var.disk_autoresize_limit
disk_size = var.disk_size
disk_type = var.disk_type
pricing_plan = var.pricing_plan
dynamic "database_flags" {
for_each = var.database_flags
content {
Expand Down
6 changes: 6 additions & 0 deletions modules/mssql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ variable "disk_autoresize" {
default = true
}

variable "disk_autoresize_limit" {
description = "The maximum size to which storage can be auto increased."
type = number
default = 0
}

variable "disk_size" {
description = "The disk size for the master instance."
default = 10
Expand Down
3 changes: 2 additions & 1 deletion modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| delete\_timeout | The optional timout that is applied to limit long database deletes. | `string` | `"10m"` | no |
| deletion\_protection | Used to block Terraform from deleting a SQL Instance. | `bool` | `true` | no |
| disk\_autoresize | Configuration to increase storage size | `bool` | `true` | no |
| disk\_autoresize\_limit | The maximum size to which storage can be auto increased. | `number` | `0` | no |
| disk\_size | The disk size for the master instance | `number` | `10` | no |
| disk\_type | The disk type for the master instance. | `string` | `"PD_SSD"` | no |
| enable\_default\_db | Enable or disable the creation of the default database | `bool` | `true` | no |
Expand All @@ -37,7 +38,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | `bool` | `false` | no |
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_autoresize_limit = number<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
| tier | The tier for the master instance. | `string` | `"db-n1-standard-1"` | no |
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"10m"` | no |
Expand Down
3 changes: 2 additions & 1 deletion modules/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ resource "google_sql_database_instance" "default" {
}
}

disk_autoresize = var.disk_autoresize
disk_autoresize = var.disk_autoresize
disk_autoresize_limit = var.disk_autoresize_limit

disk_size = var.disk_size
disk_type = var.disk_type
Expand Down
11 changes: 6 additions & 5 deletions modules/mysql/read_replica.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ resource "google_sql_database_instance" "replicas" {
}
}

disk_autoresize = lookup(each.value, "disk_autoresize", var.disk_autoresize)
disk_size = lookup(each.value, "disk_size", var.disk_size)
disk_type = lookup(each.value, "disk_type", var.disk_type)
pricing_plan = "PER_USE"
user_labels = lookup(each.value, "user_labels", var.user_labels)
disk_autoresize = lookup(each.value, "disk_autoresize", var.disk_autoresize)
disk_autoresize_limit = lookup(each.value, "disk_autoresize_limit", var.disk_autoresize_limit)
disk_size = lookup(each.value, "disk_size", var.disk_size)
disk_type = lookup(each.value, "disk_type", var.disk_type)
pricing_plan = "PER_USE"
user_labels = lookup(each.value, "user_labels", var.user_labels)

dynamic "database_flags" {
for_each = lookup(each.value, "database_flags", [])
Expand Down
21 changes: 14 additions & 7 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ variable "disk_autoresize" {
default = true
}

variable "disk_autoresize_limit" {
description = "The maximum size to which storage can be auto increased."
type = number
default = 0
}

variable "disk_size" {
description = "The disk size for the master instance"
type = number
Expand Down Expand Up @@ -169,13 +175,14 @@ variable "ip_configuration" {
variable "read_replicas" {
description = "List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption_key_name = null"
type = list(object({
name = string
tier = string
zone = string
disk_type = string
disk_autoresize = bool
disk_size = string
user_labels = map(string)
name = string
tier = string
zone = string
disk_type = string
disk_autoresize = bool
disk_autoresize_limit = number
disk_size = string
user_labels = map(string)
database_flags = list(object({
name = string
value = 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 @@ -21,6 +21,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| delete\_timeout | The optional timout that is applied to limit long database deletes. | `string` | `"15m"` | no |
| deletion\_protection | Used to block Terraform from deleting a SQL Instance. | `bool` | `true` | no |
| disk\_autoresize | Configuration to increase storage size. | `bool` | `true` | no |
| disk\_autoresize\_limit | The maximum size to which storage can be auto increased. | `number` | `0` | no |
| disk\_size | The disk size for the master instance. | `number` | `10` | no |
| disk\_type | The disk type for the master instance. | `string` | `"PD_SSD"` | no |
| enable\_default\_db | Enable or disable the creation of the default database | `bool` | `true` | no |
Expand All @@ -39,7 +40,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | `bool` | `false` | no |
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> tier = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_autoresize_limit = number<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
| tier | The tier for the master instance. | `string` | `"db-f1-micro"` | no |
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"15m"` | no |
Expand Down
Loading

0 comments on commit e07f141

Please sign in to comment.