- A PostgreSQL role on an existing branch, to give an application or a team member short-lived credentials for a shared database
- A new branch with its own read-write compute, to give a preview environment, a CI run, or a debugging session its own copy of the parent branch’s schema and data
Prerequisites
- A Neon API key, which you can create in the Neon Console under Organization settings > API keys (an organization API key or a project-scoped API key works)
- The ID of your Neon project (for example,
shiny-wind-028834), which the Neon Console shows in the project’s Settings - For leases that create roles, the ID of the branch to create the roles on (for example,
br-aged-salad-637688), which the Neon Console shows on the project’s Branches page - A role in the Infisical project that lets you create dynamic secrets
Step 1: Create the dynamic secret
1
In your project, go to the environment and folder where you want the dynamic secret, then select Add New > Add Dynamic Secret.
2
Select Neon.
3
Fill in the form:
How long a lease lasts if the person creating it doesn’t choose a TTL (for example,
1h).Your Neon API key. When you edit the dynamic secret, leave this blank to keep the current key.
The resource that each lease creates in Neon. Select A PostgreSQL role for a role on an existing branch, or A database branch for a new branch. The fields that follow depend on your choice.
- A PostgreSQL role
- A database branch
Turn this on to get Neon’s pooled connection string instead of a direct connection string. The host in a pooled connection string includes
-pooler.4
Select Submit.Before Infisical saves the dynamic secret, it checks that:
- The API key can access the project
- The branch exists (Infisical checks the project’s default branch if you left Parent Branch ID empty)
- The database exists on that branch
- For branch leases, the role exists
Step 2: Create a lease
1
In the row for the dynamic secret, select Generate Lease.
2
Enter a Default TTL for the lease, then select Provision Lease.Infisical waits for Neon to finish creating the role or branch, so the credentials work as soon as Infisical shows them.
3
Copy the values Infisical shows:
DATABASE_URL: the full PostgreSQL connection stringDB_HOST,DB_NAME,DB_USERNAME, andDB_PASSWORD: the host, database, role, and password from the connection stringBRANCH_IDandBRANCH_NAME: the ID and name of the new branch (branch leases only)
Revoke a lease
Select the dynamic secret to see its leases, then select Revoke lease next to a lease to delete its role or branch in Neon before the lease expires. When a lease expires, Infisical deletes its role or branch automatically. In both cases, Infisical revokes the lease only after Neon finishes deleting the role or branch. Infisical still revokes the lease if the role or branch was already deleted, for example in the Neon Console or when the branch reached its expiration time in Neon. While the dynamic secret has active leases, you can’t change its Project ID, Each Lease Creates, or Branch ID, because Infisical needs those values to delete the roles and branches of the leases. To change one of these fields, revoke the active leases first.Renew a lease
1
Select the dynamic secret to see its leases, then select Renew lease next to a lease.
2
Enter the TTL to add to the lease, then select Renew Lease.