Skip to content

Commit 7d6b209

Browse files
ravisiddhubharathkkbrenovate[bot]g-awmalikcloud-foundation-bot
authored
feat!: Aligned the behaviour of additional_users resource in all 3 Cloud SQL instance modules. (#398)
Co-authored-by: Bharath KKB <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: g-awmalik <[email protected]> Co-authored-by: Awais Malik <[email protected]> Co-authored-by: CFT Bot <[email protected]>
1 parent 55f4206 commit 7d6b209

File tree

26 files changed

+251
-88
lines changed

26 files changed

+251
-88
lines changed

docs/upgrading_to_sql_db_14.0.0.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Upgrading to SQL DB 14.0.0
22

3-
The 14.0.0 release of SQL DB is a backward incompatible release. This incompatibility affects `postgresql` submodule that uses IAM authentication.
3+
The 14.0.0 release of SQL DB is a backward incompatible release. This incompatibility affects `postgresql` submodule that uses IAM authentication. It also affects `additional_users` variable in all 3 modules.
44

55
## Migration Instructions
66

@@ -113,3 +113,111 @@ done
113113
```
114114

115115
After IAM bindings are moved, **terraform apply should be without any changes**.
116+
117+
### Added `random_password` field in `additional_users` variable in postgresql module
118+
This change is in effort to align the behavior of `additional_users` variable in all the modules. Setting `random_password` field generates a random password for the user. Exactly one of `password` or `random_password` should be set.
119+
120+
```diff
121+
module "pg" {
122+
source = "GoogleCloudPlatform/sql-db/google//modules/postgresql"
123+
- version = "~> 13.0"
124+
+ version = "~> 14.0"
125+
126+
name = "test"
127+
database_version = "POSTGRES_14"
128+
project_id = var.project_id
129+
zone = "europe-west1-b"
130+
region = "europe-west1"
131+
tier = "db-custom-1-3840"
132+
133+
additional_users = [
134+
{
135+
name = "john"
136+
password = "password"
137+
+ random_password = false
138+
}
139+
]
140+
}
141+
```
142+
143+
### Added `random_password` field in `additional_users` variable in mssql module
144+
This change is in effort to align the behavior of `additional_users` variable in all the modules. Setting `random_password` field generates a random password for the user. At most one of `password` or `random_password` should be set.
145+
146+
```diff
147+
module "mssql" {
148+
source = "GoogleCloudPlatform/sql-db/google//modules/mssql"
149+
- version = "~> 13.0"
150+
+ version = "~> 14.0"
151+
152+
name = "test"
153+
database_version = "SQLSERVER_2017_STANDARD"
154+
project_id = var.project_id
155+
zone = "europe-west1-b"
156+
region = "europe-west1"
157+
tier = "db-custom-1-3840"
158+
159+
additional_users = [
160+
{
161+
name = "john"
162+
password = "password"
163+
+ random_password = false
164+
}
165+
]
166+
}
167+
```
168+
169+
### Changed the variable type of `additional_users` in mysql module
170+
This change is in effort to align the behavior of `additional_users` variable in all the modules. Setting `random_password` field generates a random password for the user. At most one of `password` or `random_password` should be set. `user_host` would be the host value for the additional users if the `host` field is set as `null`. You can use `type` to create IAM users.
171+
172+
```diff
173+
module "mysql" {
174+
source = "GoogleCloudPlatform/sql-db/google//modules/mysql"
175+
- version = "~> 13.0"
176+
+ version = "~> 14.0"
177+
178+
name = "test"
179+
database_version = "MYSQL_8_0"
180+
project_id = var.project_id
181+
zone = "europe-west1-b"
182+
region = "europe-west1"
183+
tier = "db-custom-1-3840"
184+
185+
additional_users = [
186+
{
187+
name = "john"
188+
password = "password"
189+
+ random_password = false
190+
+ host = null
191+
+ type = null
192+
}
193+
]
194+
}
195+
```
196+
197+
### Added `random_password` field in `additional_users` variable in safer_mysql module
198+
This change is in effort to align the behavior of `additional_users` variable in all the modules. Setting `random_password` field generates a random password for the user. At most one of `password` or `random_password` should be set.
199+
200+
```diff
201+
module "smysql" {
202+
source = "GoogleCloudPlatform/sql-db/google//modules/safer_mysql"
203+
- version = "~> 13.0"
204+
+ version = "~> 14.0"
205+
206+
name = "test"
207+
database_version = "MYSQL_8_0"
208+
project_id = var.project_id
209+
zone = "europe-west1-b"
210+
region = "europe-west1"
211+
tier = "db-custom-1-3840"
212+
213+
additional_users = [
214+
{
215+
name = "john"
216+
password = "password"
217+
type = "BUILT_IN"
218+
host = "%"
219+
+ random_password = false
220+
}
221+
]
222+
}
223+
```

examples/mysql-ha/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,18 @@ module "mysql" {
143143

144144
additional_users = [
145145
{
146-
name = "tftest2"
147-
password = "abcdefg"
148-
host = "localhost"
149-
type = "BUILT_IN"
146+
name = "tftest2"
147+
password = "abcdefg"
148+
host = "localhost"
149+
type = "BUILT_IN"
150+
random_password = false
150151
},
151152
{
152-
name = "tftest3"
153-
password = "abcdefg"
154-
host = "localhost"
155-
type = "BUILT_IN"
153+
name = "tftest3"
154+
password = "abcdefg"
155+
host = "localhost"
156+
type = "BUILT_IN"
157+
random_password = false
156158
},
157159
]
158160
}

examples/mysql-private/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,18 @@ module "safer-mysql-db" {
6060
// Cloud SQL proxy.
6161
additional_users = [
6262
{
63-
name = "app"
64-
password = "PaSsWoRd"
65-
host = "localhost"
66-
type = "BUILT_IN"
63+
name = "app"
64+
password = "PaSsWoRd"
65+
host = "localhost"
66+
type = "BUILT_IN"
67+
random_password = false
6768
},
6869
{
69-
name = "readonly"
70-
password = "PaSsWoRd"
71-
host = "localhost"
72-
type = "BUILT_IN"
70+
name = "readonly"
71+
password = "PaSsWoRd"
72+
host = "localhost"
73+
type = "BUILT_IN"
74+
random_password = false
7375
},
7476
]
7577

examples/postgresql-ha/main.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,16 @@ module "pg" {
141141

142142
additional_users = [
143143
{
144-
name = "tftest2"
145-
password = "abcdefg"
146-
host = "localhost"
144+
name = "tftest2"
145+
password = "abcdefg"
146+
host = "localhost"
147+
random_password = false
147148
},
148149
{
149-
name = "tftest3"
150-
password = "abcdefg"
151-
host = "localhost"
150+
name = "tftest3"
151+
password = "abcdefg"
152+
host = "localhost"
153+
random_password = false
152154
},
153155
]
154156
}

examples/postgresql-public-iam/main.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ module "postgresql-db" {
5454

5555
additional_users = [
5656
{
57-
name = "tftest2"
58-
password = "Ex@mp!e1"
59-
host = "localhost"
57+
name = "tftest2"
58+
password = "Ex@mp!e1"
59+
host = "localhost"
60+
random_password = false
6061
},
6162
{
62-
name = "tftest3"
63-
password = "Ex@mp!e2"
64-
host = "localhost"
63+
name = "tftest3"
64+
password = "Ex@mp!e2"
65+
host = "localhost"
66+
random_password = false
6567
},
6668
]
6769

metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Google LLC
1+
# Copyright 2023 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

modules/backup/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Google LLC
1+
# Copyright 2023 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

modules/mssql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The following dependency must be available for SQL Server module:
1212
| activation\_policy | The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | `string` | `"ALWAYS"` | no |
1313
| active\_directory\_config | Active domain that the SQL instance will join. | `map(string)` | `{}` | no |
1414
| additional\_databases | A list of databases to be created in your cluster | <pre>list(object({<br> name = string<br> charset = string<br> collation = string<br> }))</pre> | `[]` | no |
15-
| additional\_users | A list of users to be created in your cluster | <pre>list(object({<br> name = string<br> password = string<br> }))</pre> | `[]` | no |
15+
| additional\_users | A list of users to be created in your cluster. A random password would be set for the user if the `random_password` variable is set. | <pre>list(object({<br> name = string<br> password = string<br> random_password = bool<br> }))</pre> | `[]` | no |
1616
| availability\_type | The availability type for the master instance.This is only used to set up high availability for the MSSQL instance. Can be either `ZONAL` or `REGIONAL`. | `string` | `"ZONAL"` | no |
1717
| backup\_configuration | The database backup configuration. | <pre>object({<br> binary_log_enabled = bool<br> enabled = bool<br> point_in_time_recovery_enabled = bool<br> start_time = string<br> transaction_log_retention_days = string<br> retained_backups = number<br> retention_unit = string<br> })</pre> | <pre>{<br> "binary_log_enabled": null,<br> "enabled": false,<br> "point_in_time_recovery_enabled": null,<br> "retained_backups": null,<br> "retention_unit": null,<br> "start_time": null,<br> "transaction_log_retention_days": null<br>}</pre> | no |
1818
| create\_timeout | The optional timeout that is applied to limit long database creates. | `string` | `"15m"` | no |

modules/mssql/main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,11 @@ resource "random_password" "user-password" {
184184
}
185185

186186
resource "random_password" "additional_passwords" {
187-
for_each = local.users
188-
length = 8
187+
for_each = local.users
188+
keepers = {
189+
name = google_sql_database_instance.default.name
190+
}
191+
length = 32
189192
special = true
190193
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
191194
}
@@ -202,7 +205,7 @@ resource "google_sql_user" "additional_users" {
202205
for_each = local.users
203206
project = var.project_id
204207
name = each.value.name
205-
password = lookup(each.value, "password", random_password.additional_passwords[each.value.name].result)
208+
password = each.value.random_password ? random_password.additional_passwords[each.value.name].result : each.value.password
206209
instance = google_sql_database_instance.default.name
207210
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
208211
}

modules/mssql/metadata.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Google LLC
1+
# Copyright 2023 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -68,11 +68,12 @@ spec:
6868
default: []
6969
required: false
7070
- name: additional_users
71-
description: A list of users to be created in your cluster
71+
description: A list of users to be created in your cluster. A random password would be set for the user if the `random_password` variable is set.
7272
type: |-
7373
list(object({
74-
name = string
75-
password = string
74+
name = string
75+
password = string
76+
random_password = bool
7677
}))
7778
default: []
7879
required: false

0 commit comments

Comments
 (0)