Databases And Persistence /
Connect database secrets to workloads
Databases can be accessed and used by services within the same project.
The way you connect to your database will depend on the implementation in your application or service. Your deployment should be configured to receive connection details from runtime variables.
Open the connection details page in your database to view the relevant connection strings and secrets, which you can use to connect to the database from your deployments. You can either add these manually to a specific deployment or secret group, or link the variables to a secret group.
You should not use the administration connection string or administrator account to connect from your deployments, unless deploying a secured administration interface.
You can link a database to a secret group so that the desired secrets are inherited as variables within that secret group.
These secrets can then be used in any services and jobs that inherit from that secret group.
You can link a database's secrets to a secret group from:
- the addon creation form
- the secret group creation form
- an addon connection details page
- a secret group's linked addons page
You can select the suggested variables to automatically include the most useful and commonly used connection details, or manually select which variables to include.
Variables names are generated using the database name and connection detail, e.g.
NF_MY-DATABASE_HOST. If your application is expecting certain variable names you can give aliases to the variables, for example adding
ENV_DB_HOST as aliases to
NF_MY-DATABASE_HOST means that the variable can be accessed by all three of the aliases in the environment.
After linking the variables they will be available in any service that inherits from that project secret group.