Skip to content

fix: Add full subnet group name when prefix is enabled #359

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/complete-postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ module "db_default" {
subnet_ids = module.vpc.database_subnets
vpc_security_group_ids = [module.security_group.security_group_id]

db_subnet_group_use_name_prefix = true
db_subnet_group_name = "complete_postgresql"

maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00"

Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
master_password = var.create_db_instance && var.create_random_password ? random_password.master_password[0].result : var.password
db_subnet_group_name = !var.cross_region_replica && var.replicate_source_db != null ? null : coalesce(var.db_subnet_group_name, module.db_subnet_group.db_subnet_group_id, var.identifier)
db_subnet_group_name = ! var.cross_region_replica && var.replicate_source_db != null ? null : var.create_db_subnet_group ? module.db_subnet_group.db_subnet_group_id : coalesce(var.db_subnet_group_name, var.identifier)
Copy link
Member

Choose a reason for hiding this comment

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

this can actually be more succinctly fixed with:

Suggested change
db_subnet_group_name = ! var.cross_region_replica && var.replicate_source_db != null ? null : var.create_db_subnet_group ? module.db_subnet_group.db_subnet_group_id : coalesce(var.db_subnet_group_name, var.identifier)
db_subnet_group_name = !var.cross_region_replica && var.replicate_source_db != null ? null : try(module.db_subnet_group.db_subnet_group_id, var.db_subnet_group_name)

what this does is:

  1. Try to get the computed subnet group ID, if that fails
  2. Use the var.db_subnet_group_name

I can't see a scenario where we don't can get past both the created or provided subnet group names so we can drop the var.identifier here


parameter_group_name_id = var.create_db_parameter_group ? module.db_parameter_group.db_parameter_group_id : var.parameter_group_name

Expand Down