Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketzacoatl/0bbdd013ac6cf144403978158e8deee9 to your computer and use it in GitHub Desktop.
Save ketzacoatl/0bbdd013ac6cf144403978158e8deee9 to your computer and use it in GitHub Desktop.
locals {
# we have to fixup the master username before we use it, the AWS API will error out otherwise
# RDS expects the username to be without hyphens and 16 characters at max. 'rdsadmin' is also
# a forbidden username, though we don't validate that here.
db_master_user_unsanitized = "${var.app_db_master_user}"
# truncate to 16 characters, but deal with the fact that substr() will error out if you ask
# for more characters than are in the string
default_master_user_max_length = "16"
master_user_length = "${length(local.db_master_user_unsanitized)}"
master_user_max_length = "${local.master_user_length < local.default_master_user_max_length ? local.master_user_length : local.default_master_user_max_length}"
db_master_user_truncated = "${substr(local.db_master_user_unsanitized, 0, local.master_user_max_length)}"
# remove hyphens from the username
db_master_user = "${replace(local.db_master_user_truncated, "-", "")}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment