Can I use environment variables in my profile?
Yes! Any field in profiles.yml can reference an environment variable using the env_var() Jinja function:
my_project:
target: dev
outputs:
dev:
type: postgres
host: localhost
user: "{{ env_var('DBT_DEV_USER') }}"
password: "{{ env_var('DBT_DEV_PASSWORD') }}"
schema: "dbt_{{ env_var('DBT_USERNAME') }}"
port: 5432
threads: 4
This keeps sensitive credentials out of version control. Set the variables in your shell before running dbt:
export DBT_DEV_USER=alice
export DBT_DEV_PASSWORD=my_password
export DBT_USERNAME=alice
You can supply a default value as the second argument to avoid compilation errors when a variable isn't set:
schema: "dbt_{{ env_var('DBT_USERNAME', 'default') }}"
For a full walkthrough of how to configure separate dev, CI, and prod environments using env vars, see dbt Core environments.
Was this page helpful?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
0