Skip to content

Commit e07f141

Browse files
feat!: Add support for setting disk_autoresize_limit (#288)
* 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 <[email protected]> Co-authored-by: Bharath KKB <[email protected]>
1 parent 449f1a2 commit e07f141

File tree

23 files changed

+246
-108
lines changed

23 files changed

+246
-108
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The current version is 3.X. The following guides are available to assist with up
2323

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

2729
## Root module
2830

docs/upgrading_to_sql_db_11.0.0.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Upgrading to SQL DB 11.0.0
2+
3+
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.
4+
5+
## Migration Instructions
6+
7+
Prior to the 11.0.0 release, all instances could only be created without a limit.
8+
9+
```hcl
10+
module "pg" {
11+
source = "GoogleCloudPlatform/sql-db/google//modules/postgresql"
12+
version = "~> 10.0"
13+
14+
project_id = var.project_id
15+
region = "europe-west1"
16+
zone = "europe-west1-d"
17+
name = "test"
18+
random_instance_name = true
19+
availability_type = "ZONAL"
20+
database_version = "POSTGRES_14"
21+
disk_type = "PD_HDD"
22+
disk_size = 10
23+
disk_autoresize = true
24+
create_timeout = "30m"
25+
26+
read_replicas = [
27+
{
28+
name = "0"
29+
zone = "europe-west1-d"
30+
tier = "db-f1-micro"
31+
disk_type = "PD_HDD"
32+
disk_size = 10
33+
disk_autoresize = true
34+
encryption_key_name = null
35+
database_flags = []
36+
user_labels = {}
37+
38+
ip_configuration = {
39+
allocated_ip_range = null
40+
authorized_networks = []
41+
ipv4_enabled = true
42+
private_network = null
43+
require_ssl = false
44+
}
45+
},
46+
]
47+
}
48+
```
49+
50+
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.
51+
52+
```diff
53+
module "pg" {
54+
source = "GoogleCloudPlatform/sql-db/google//modules/postgresql"
55+
- version = "~> 10.0"
56+
+ version = "~> 11.0"
57+
58+
project_id = var.project_id
59+
region = "europe-west1"
60+
zone = "europe-west1-d"
61+
name = "test"
62+
random_instance_name = true
63+
availability_type = "ZONAL"
64+
database_version = "POSTGRES_14"
65+
disk_type = "PD_HDD"
66+
disk_size = 10
67+
disk_autoresize = true
68+
create_timeout = "30m"
69+
70+
read_replicas = [
71+
{
72+
name = "0"
73+
zone = "europe-west1-d"
74+
tier = "db-f1-micro"
75+
disk_type = "PD_HDD"
76+
disk_size = 10
77+
disk_autoresize = true
78+
+ disk_autoresize_limit = 0
79+
encryption_key_name = null
80+
database_flags = []
81+
user_labels = {}
82+
83+
ip_configuration = {
84+
allocated_ip_range = null
85+
authorized_networks = []
86+
ipv4_enabled = true
87+
private_network = null
88+
require_ssl = false
89+
}
90+
},
91+
]
92+
}
93+
```

examples/mysql-ha/main.tf

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,43 @@ module "mysql" {
8282
read_replica_name_suffix = "-test"
8383
read_replicas = [
8484
{
85-
name = "0"
86-
zone = "us-central1-a"
87-
tier = "db-n1-standard-1"
88-
ip_configuration = local.read_replica_ip_configuration
89-
database_flags = [{ name = "long_query_time", value = 1 }]
90-
disk_autoresize = null
91-
disk_size = null
92-
disk_type = "PD_HDD"
93-
user_labels = { bar = "baz" }
94-
encryption_key_name = null
85+
name = "0"
86+
zone = "us-central1-a"
87+
tier = "db-n1-standard-1"
88+
ip_configuration = local.read_replica_ip_configuration
89+
database_flags = [{ name = "long_query_time", value = 1 }]
90+
disk_autoresize = null
91+
disk_autoresize_limit = null
92+
disk_size = null
93+
disk_type = "PD_HDD"
94+
user_labels = { bar = "baz" }
95+
encryption_key_name = null
9596
},
9697
{
97-
name = "1"
98-
zone = "us-central1-b"
99-
tier = "db-n1-standard-1"
100-
ip_configuration = local.read_replica_ip_configuration
101-
database_flags = [{ name = "long_query_time", value = 1 }]
102-
disk_autoresize = null
103-
disk_size = null
104-
disk_type = "PD_HDD"
105-
user_labels = { bar = "baz" }
106-
encryption_key_name = null
98+
name = "1"
99+
zone = "us-central1-b"
100+
tier = "db-n1-standard-1"
101+
ip_configuration = local.read_replica_ip_configuration
102+
database_flags = [{ name = "long_query_time", value = 1 }]
103+
disk_autoresize = null
104+
disk_autoresize_limit = null
105+
disk_size = null
106+
disk_type = "PD_HDD"
107+
user_labels = { bar = "baz" }
108+
encryption_key_name = null
107109
},
108110
{
109-
name = "2"
110-
zone = "us-central1-c"
111-
tier = "db-n1-standard-1"
112-
ip_configuration = local.read_replica_ip_configuration
113-
database_flags = [{ name = "long_query_time", value = 1 }]
114-
disk_autoresize = null
115-
disk_size = null
116-
disk_type = "PD_HDD"
117-
user_labels = { bar = "baz" }
118-
encryption_key_name = null
111+
name = "2"
112+
zone = "us-central1-c"
113+
tier = "db-n1-standard-1"
114+
ip_configuration = local.read_replica_ip_configuration
115+
database_flags = [{ name = "long_query_time", value = 1 }]
116+
disk_autoresize = null
117+
disk_autoresize_limit = null
118+
disk_size = null
119+
disk_type = "PD_HDD"
120+
user_labels = { bar = "baz" }
121+
encryption_key_name = null
119122
},
120123
]
121124

examples/postgresql-ha/main.tf

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,43 @@ module "pg" {
8181
read_replica_name_suffix = "-test"
8282
read_replicas = [
8383
{
84-
name = "0"
85-
zone = "us-central1-a"
86-
tier = "db-custom-1-3840"
87-
ip_configuration = local.read_replica_ip_configuration
88-
database_flags = [{ name = "autovacuum", value = "off" }]
89-
disk_autoresize = null
90-
disk_size = null
91-
disk_type = "PD_HDD"
92-
user_labels = { bar = "baz" }
93-
encryption_key_name = null
84+
name = "0"
85+
zone = "us-central1-a"
86+
tier = "db-custom-1-3840"
87+
ip_configuration = local.read_replica_ip_configuration
88+
database_flags = [{ name = "autovacuum", value = "off" }]
89+
disk_autoresize = null
90+
disk_autoresize_limit = null
91+
disk_size = null
92+
disk_type = "PD_HDD"
93+
user_labels = { bar = "baz" }
94+
encryption_key_name = null
9495
},
9596
{
96-
name = "1"
97-
zone = "us-central1-b"
98-
tier = "db-custom-1-3840"
99-
ip_configuration = local.read_replica_ip_configuration
100-
database_flags = [{ name = "autovacuum", value = "off" }]
101-
disk_autoresize = null
102-
disk_size = null
103-
disk_type = "PD_HDD"
104-
user_labels = { bar = "baz" }
105-
encryption_key_name = null
97+
name = "1"
98+
zone = "us-central1-b"
99+
tier = "db-custom-1-3840"
100+
ip_configuration = local.read_replica_ip_configuration
101+
database_flags = [{ name = "autovacuum", value = "off" }]
102+
disk_autoresize = null
103+
disk_autoresize_limit = null
104+
disk_size = null
105+
disk_type = "PD_HDD"
106+
user_labels = { bar = "baz" }
107+
encryption_key_name = null
106108
},
107109
{
108-
name = "2"
109-
zone = "us-central1-c"
110-
tier = "db-custom-1-3840"
111-
ip_configuration = local.read_replica_ip_configuration
112-
database_flags = [{ name = "autovacuum", value = "off" }]
113-
disk_autoresize = null
114-
disk_size = null
115-
disk_type = "PD_HDD"
116-
user_labels = { bar = "baz" }
117-
encryption_key_name = null
110+
name = "2"
111+
zone = "us-central1-c"
112+
tier = "db-custom-1-3840"
113+
ip_configuration = local.read_replica_ip_configuration
114+
database_flags = [{ name = "autovacuum", value = "off" }]
115+
disk_autoresize = null
116+
disk_autoresize_limit = null
117+
disk_size = null
118+
disk_type = "PD_HDD"
119+
user_labels = { bar = "baz" }
120+
encryption_key_name = null
118121
},
119122
]
120123

modules/mssql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The following dependency must be available for SQL Server module:
2424
| delete\_timeout | The optional timeout that is applied to limit long database deletes. | `string` | `"30m"` | no |
2525
| deletion\_protection | Used to block Terraform from deleting a SQL Instance. | `bool` | `true` | no |
2626
| disk\_autoresize | Configuration to increase storage size. | `bool` | `true` | no |
27+
| disk\_autoresize\_limit | The maximum size to which storage can be auto increased. | `number` | `0` | no |
2728
| disk\_size | The disk size for the master instance. | `number` | `10` | no |
2829
| disk\_type | The disk type for the master instance. | `string` | `"PD_SSD"` | no |
2930
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | `string` | `null` | no |

modules/mssql/main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ resource "google_sql_database_instance" "default" {
9191
}
9292
}
9393

94-
disk_autoresize = var.disk_autoresize
95-
disk_size = var.disk_size
96-
disk_type = var.disk_type
97-
pricing_plan = var.pricing_plan
94+
disk_autoresize = var.disk_autoresize
95+
disk_autoresize_limit = var.disk_autoresize_limit
96+
disk_size = var.disk_size
97+
disk_type = var.disk_type
98+
pricing_plan = var.pricing_plan
9899
dynamic "database_flags" {
99100
for_each = var.database_flags
100101
content {

modules/mssql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ variable "disk_autoresize" {
7474
default = true
7575
}
7676

77+
variable "disk_autoresize_limit" {
78+
description = "The maximum size to which storage can be auto increased."
79+
type = number
80+
default = 0
81+
}
82+
7783
variable "disk_size" {
7884
description = "The disk size for the master instance."
7985
default = 10

modules/mysql/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
2121
| delete\_timeout | The optional timout that is applied to limit long database deletes. | `string` | `"10m"` | no |
2222
| deletion\_protection | Used to block Terraform from deleting a SQL Instance. | `bool` | `true` | no |
2323
| disk\_autoresize | Configuration to increase storage size | `bool` | `true` | no |
24+
| disk\_autoresize\_limit | The maximum size to which storage can be auto increased. | `number` | `0` | no |
2425
| disk\_size | The disk size for the master instance | `number` | `10` | no |
2526
| disk\_type | The disk type for the master instance. | `string` | `"PD_SSD"` | no |
2627
| enable\_default\_db | Enable or disable the creation of the default database | `bool` | `true` | no |
@@ -37,7 +38,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
3738
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | `bool` | `false` | no |
3839
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
3940
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
40-
| 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 |
41+
| 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 |
4142
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
4243
| tier | The tier for the master instance. | `string` | `"db-n1-standard-1"` | no |
4344
| update\_timeout | The optional timout that is applied to limit long database updates. | `string` | `"10m"` | no |

modules/mysql/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ resource "google_sql_database_instance" "default" {
9292
}
9393
}
9494

95-
disk_autoresize = var.disk_autoresize
95+
disk_autoresize = var.disk_autoresize
96+
disk_autoresize_limit = var.disk_autoresize_limit
9697

9798
disk_size = var.disk_size
9899
disk_type = var.disk_type

modules/mysql/read_replica.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ resource "google_sql_database_instance" "replicas" {
5858
}
5959
}
6060

61-
disk_autoresize = lookup(each.value, "disk_autoresize", var.disk_autoresize)
62-
disk_size = lookup(each.value, "disk_size", var.disk_size)
63-
disk_type = lookup(each.value, "disk_type", var.disk_type)
64-
pricing_plan = "PER_USE"
65-
user_labels = lookup(each.value, "user_labels", var.user_labels)
61+
disk_autoresize = lookup(each.value, "disk_autoresize", var.disk_autoresize)
62+
disk_autoresize_limit = lookup(each.value, "disk_autoresize_limit", var.disk_autoresize_limit)
63+
disk_size = lookup(each.value, "disk_size", var.disk_size)
64+
disk_type = lookup(each.value, "disk_type", var.disk_type)
65+
pricing_plan = "PER_USE"
66+
user_labels = lookup(each.value, "user_labels", var.user_labels)
6667

6768
dynamic "database_flags" {
6869
for_each = lookup(each.value, "database_flags", [])

0 commit comments

Comments
 (0)