-
Notifications
You must be signed in to change notification settings - Fork 411
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
Added: random_id for mysql instance name #116
Added: random_id for mysql instance name #116
Conversation
Added: random_id for cloudsql
I'm not sure we want to include this in the module. While it's indeed necessary for recreating instances after deletion, it's also following a very specific pattern which doesn't necessarily match what everyone wants. |
Maybe, it would be nice to have that as an option. Like resource "random_id" "prefix" {
byte_length = 4
}
resource "google_sql_database_instance" "default" {
provider = google-beta
project = var.project_id
name = var.instance_name_prefix ? "${var.name}-${random_id.prefix.hex}" : var.name How does it sound to you? |
Yeah I think we could make it optional with a |
@morgante Updated the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, just some nits. It'd also be nice to have this added to all the submodules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing as you need to index for the random ID:
Error: Missing resource instance key
on ../../../modules/mssql/main.tf line 43, in resource "google_sql_database_instance" "default":
43: name = var.random_instance_name ? "${var.name}-${random_id.suffix.hex}" : var.name
Because random_id.suffix has "count" set, its attributes must be accessed on
specific instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution.
One more thing that I have noticed. Seems that now we don't need this part in examples resource "random_id" "suffix" {
byte_length = 5
}
locals {
/*
Random instance name needed because:
"You cannot reuse an instance name for up to a week after you have deleted an instance."
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.db_name}-${random_id.suffix.hex}"
} Now we should be able to use this module "safer-mysql-db" {
source = "../../modules/mysql"
name = var.db_name
random_instance_name = true
database_version = "MYSQL_5_6"
project_id = var.project_id |
Indeed! Looks like that example could be cleaned up. We can also remove random_Id from safer-mysql and just pass through the Do you mind doing a follow-up PR to fix those issues? |
There is an issue if you would like to create a DB with the same name. With the current approach, you need to change the name every time or you have to work around and use something like
random_id
More information is here Managing Your Instances