rill icon indicating copy to clipboard operation
rill copied to clipboard

[docs] Rill Developer: Templating and environment variables: unclear how to use .env

Open shiv-io opened this issue 5 months ago • 1 comments

Describe the bug Having gone through https://docs.rilldata.com/build/credentials/ and https://docs.rilldata.com/deploy/templating, it is still quite unclear how to use a .env file to define an environment variable and to then use that variable in a source.yaml. I've tried several guesses to make this work but haven't been able to. In particular, I am looking to define a .env with my postgres connection string and use that variable in my source.yaml.

To Reproduce Try to use a .env file to define an environment variable and then reference that variable in a postgres connection URL.

Expected behavior It would help to have examples on the docs for this, as .env files are often used by users.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

shiv-io avatar Jul 10 '25 02:07 shiv-io

Hey Shiv! Thanks for the feedback!

Here's a quick example of using the environmental variables for a source:

type: source

connector: "postgres"
sql: |
  select * from {{.env.table}}

dsn: '{{.env.db_type}}://...'

where the .env is defined as

table="rna"
db_type="postgres"

I'm actually working on making our docs more friendly that would add a templating and project defaults to each object type in Rill (source, model, metrics...) Sounds like this is a timely effort given the feedback :)

royendo avatar Jul 10 '25 14:07 royendo