Skip to content

Commit 0ceb0ed

Browse files
ravisiddhubharathkkbrenovate[bot]g-awmalikcloud-foundation-bot
authored
fix: random password for default user and additional users will also follow password validation policy (#443)
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 7d98bda commit 0ceb0ed

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

modules/mysql/main.tf

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,27 @@ resource "random_password" "user-password" {
188188
name = google_sql_database_instance.default.name
189189
}
190190

191-
length = 32
192-
special = var.enable_random_password_special
193-
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
191+
min_lower = 1
192+
min_numeric = 1
193+
min_upper = 1
194+
length = var.password_validation_policy_config != null ? (var.password_validation_policy_config.min_length != null ? var.password_validation_policy_config.min_length + 4 : 32) : 32
195+
special = var.enable_random_password_special ? true : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? true : false) : false)
196+
min_special = var.enable_random_password_special ? 1 : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? 1 : 0) : 0)
197+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
194198
}
195199

196200
resource "random_password" "additional_passwords" {
197201
for_each = local.users
198202
keepers = {
199203
name = google_sql_database_instance.default.name
200204
}
201-
length = 32
202-
special = var.enable_random_password_special
203-
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
205+
min_lower = 1
206+
min_numeric = 1
207+
min_upper = 1
208+
length = var.password_validation_policy_config != null ? (var.password_validation_policy_config.min_length != null ? var.password_validation_policy_config.min_length + 4 : 32) : 32
209+
special = var.enable_random_password_special ? true : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? true : false) : false)
210+
min_special = var.enable_random_password_special ? 1 : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? 1 : 0) : 0)
211+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
204212
}
205213

206214
resource "google_sql_user" "default" {

modules/postgresql/main.tf

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,27 @@ resource "random_password" "user-password" {
197197
keepers = {
198198
name = google_sql_database_instance.default.name
199199
}
200-
201-
length = 32
202-
special = var.enable_random_password_special
203-
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
200+
min_lower = 1
201+
min_numeric = 1
202+
min_upper = 1
203+
length = var.password_validation_policy_config != null ? (var.password_validation_policy_config.min_length != null ? var.password_validation_policy_config.min_length + 4 : 32) : 32
204+
special = var.enable_random_password_special ? true : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? true : false) : false)
205+
min_special = var.enable_random_password_special ? 1 : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? 1 : 0) : 0)
206+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
204207
}
205208

206209
resource "random_password" "additional_passwords" {
207210
for_each = local.users
208211
keepers = {
209212
name = google_sql_database_instance.default.name
210213
}
211-
length = 32
212-
special = var.enable_random_password_special
213-
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
214+
min_lower = 1
215+
min_numeric = 1
216+
min_upper = 1
217+
length = var.password_validation_policy_config != null ? (var.password_validation_policy_config.min_length != null ? var.password_validation_policy_config.min_length + 4 : 32) : 32
218+
special = var.enable_random_password_special ? true : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? true : false) : false)
219+
min_special = var.enable_random_password_special ? 1 : (var.password_validation_policy_config != null ? (var.password_validation_policy_config.complexity != "COMPLEXITY_UNSPECIFIED" ? 1 : 0) : 0)
220+
depends_on = [null_resource.module_depends_on, google_sql_database_instance.default]
214221
}
215222

216223
resource "google_sql_user" "default" {

0 commit comments

Comments
 (0)