Handling Special Characters in Database Passwords
How to use a database URL that contains a password with special characters such as @
or #
?
Answer
Database URLs often contain passwords and other information that may include non-alphanumeric characters. These characters must be escaped using standard URL encoding to be parsed correctly by Atlas.
Users have two options: they can either escape these characters manually or use the urlescape
function in an atlas.hcl
configuration file to handle them automatically. For example:
locals {
db_pass = urlescape(getenv("DB_PASSWORD"))
}
env "local" {
url = "postgres://user:${local.db_pass}@localhost:5432/database"
}
For more information, see the URL section.