How services connect
When you create a database, Qovery adds built-in variables to its environment. They hold its connection details, such as its internal host name. To give one of them the name your application reads, declare an alias on the application:environment_variable_aliases for a variable, secret_aliases for a secret.
Built-in variable names follow the pattern QOVERY_<TYPE>_Z<ID>_<NAME>:
<TYPE>is the database type:POSTGRESQL,MYSQL,MONGODBorREDIS.<ID>is the first eight characters of the ID of the database, in uppercase. In Terraform:upper(split("-", qovery_database.postgres.id)[0]).<NAME>names the value.HOST_INTERNAL,PORT,LOGINandDEFAULT_DATABASE_NAMEare variables, andPASSWORDandDATABASE_URL_INTERNALare secrets.
_INTERNAL values to connect from a service that runs on the cluster. The complete list of database variables is in Credentials and connectivity. Applications, containers and Helm services have built-in variables too: see Linking Services Together.
Configuration
The database runs inCONTAINER mode, on your cluster. The application reads the connection string from DATABASE_URL, an alias of the database’s DATABASE_URL_INTERNAL secret.
variables.tf
main.tf
DATABASE_URL holds a URL of the form postgresql://<login>:<password>@<host>:<port>/<database>. The configuration never handles the password: Qovery resolves the alias when it deploys the application.
To deploy, set TF_VAR_organization_id and TF_VAR_cluster_id, then run terraform init and terraform apply, as in the basic application example.
Next steps
Multi-Environment Setup
Deploy the same stack to several environments
Linking Services Together
Connect services to each other with built-in variables
qovery_database reference
Every attribute of the database resource
Database Configuration
Container and managed databases