Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added functionality to simply specify the database version number ins… #388

Merged
merged 10 commits into from
Dec 17, 2022

Conversation

ravisiddhu
Copy link
Contributor

This PR is a fix for #373

Buganizer : b/259913441

The reason for the issue is that when using postgres module, customer assumes that since they have explicitly chosen postgres module, they only need to specify the database version number instead of the whole version name as it says in doc, but that's not the case. (Example "14" instead of "POSTGRES_14")

When customer sets the database version field as simply "14" instead of "POSTGRES_14", the instances.insert API is actually trying to create a SQL Server instance (by default the database version used is "SQLSERVER_2017_ENTERPRISE"), that is why the API is throwing an error saying "Root password is required", because SQL Server instances requires root password.

But the customer assumptions seems valid and reasonable, hence I have added a functionality in postgres module which would prepend "POSTGRES_" to database version if they have only specified the numeric part of the database version.
Example "14" to "POSTGRES_14"

Successfully passed docker_test_lint

…tead of the whole version name for postgres module.
@ravisiddhu ravisiddhu requested a review from a team as a code owner December 12, 2022 13:37
Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @ravisiddhu

modules/postgresql/main.tf Outdated Show resolved Hide resolved
@@ -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 && ((substr(var.database_version, 0, 9) == "POSTGRES_" || substr(var.database_version, 0, 9) == "postgres_") && can(regex("^\\d+(?:_?\\d)*$", substr(var.database_version, 9, -1))))) || can(regex("^\\d+(?:_?\\d)*$", var.database_version))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think we can just lower case to keep this shorter

Suggested change
condition = (length(var.database_version) >= 9 && ((substr(var.database_version, 0, 9) == "POSTGRES_" || substr(var.database_version, 0, 9) == "postgres_") && can(regex("^\\d+(?:_?\\d)*$", substr(var.database_version, 9, -1))))) || can(regex("^\\d+(?:_?\\d)*$", var.database_version))
condition = (length(var.database_version) >= 9 && (lower(substr(var.database_version, 0, 9) && can(regex("^\\d+(?:_?\\d)*$", substr(var.database_version, 9, -1))))) || can(regex("^\\d+(?:_?\\d)*$", var.database_version))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the changes based on your suggestion.

I have also added "replace(var.database_version, substr(var.database_version, 0,8), "POSTGRES")" instead of just "var.database_version", to avoid terraform drift. (This drift was because "postgres_14" was being converted to "POSTGRES_14" by the API, hence there was a difference in state file and config file, hence the fix.)

@bharathkkb bharathkkb changed the title Added functionality to simply specify the database version number ins… fix: Added functionality to simply specify the database version number ins… Dec 15, 2022
@comment-bot-dev
Copy link

@ravisiddhu
Thanks for the PR! 🚀
✅ Lint checks have passed.

@bharathkkb bharathkkb merged commit 83ca2e2 into terraform-google-modules:master Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants