Skip to content

Commit

Permalink
fix: Added functionality to simply specify the database version numbe…
Browse files Browse the repository at this point in the history
…r ins… (#388)

Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>
  • Loading branch information
ravisiddhu and bharathkkb committed Dec 17, 2022
1 parent c41015c commit 83ca2e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ resource "google_sql_database_instance" "default" {
provider = google-beta
project = var.project_id
name = local.master_instance_name
database_version = var.database_version
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")
region = var.region
encryption_key_name = var.encryption_key_name
deletion_protection = var.deletion_protection
Expand Down
5 changes: 5 additions & 0 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ variable "random_instance_name" {
variable "database_version" {
description = "The database version to use"
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\" or \"POSTGRES_14\"."
}
}

// required
Expand Down

0 comments on commit 83ca2e2

Please sign in to comment.