question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow custom variables inside profiles.yml

See original GitHub issue

Describe the feature

I would like to be able to create and set custom variables inside ~/.dbt/profiles.yml file and then use these variables within models.

Describe alternatives you’ve considered

  • Setting environment variables. However this would require further setup instructions to ask people to add variables to their .profile, .bash_rc, .zshrc etc. which requires additional command line knowledge. It would also be harder to phase more variables in and deprecate them.
  • Creating a macro that can parse a yaml file (i.e. with open('~/.dbt/profiles.yml') ... ) and setting variables from there. However this is not currently possibly.

Additional context

The goal is to make the initial setup process for installing dbt as simple as possible. A lot of the users will not have command line experience, so it’s a big step to get them to update their ~/.dbt/profiles.yml file. Therefore asking them to also maintain their own environment variables is not ideal and we would be able to provision these variables within our GitHub repo (and deploy efficiently).

This would also allow greater flexibility for what we can conditionally do inside dbt_project.yml and each of the individual models.

Who will this benefit?

The driver behind this is for everyone to set a DBT_USER_ALIAS variable that be used as a prefix to table names (inside generate_alias_name) and therefore prevent conflicts from occurring.

It will benefit those without that much command line experience, and subsequently administrators who spend time supporting them.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
cweltoncommented, Apr 27, 2022

Adding my voice to the others asking for this. Being able to set variables as part of a profile is a much cleaner solution than putting that configuration into conditional expressions or requiring additional setting of environment variables.

The choice to not implement this as a capability feels like the wrong decision.

4reactions
jtcohen6commented, Sep 23, 2020

@vembloud How many different environments are you running against? Have you considered conditional logic like:

sources:
  - name: extract
    database: "{{ 'extract_prod' if target.name == 'prod' else 'extract_dev' }}"
    schema: extract
    tables: ...

In general, we find a pretty smooth handoff point from “I’m running with a few environments and can write target-based conditional logic” to “I have a complex deployment with several environments, codified in an orchestration tool that can also reliably set environment variables.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection profiles - dbt Developer Hub
In your profiles.yml file, you can store as many profiles as you need. Typically, you would have one profile for each warehouse you...
Read more >
Allow customization to the generated profiles.yml for Dbt
It appears that the profiles. yml generated by Fivetran always sets the value of target = 'prod'. These kind of customization should be...
Read more >
How to use a YAML file or environment variables to populate ...
In most cases, we suggest using a config variables YAML file. YAML files make variables more visible, easily editable, and allow for modularization...
Read more >
54. Properties & configuration - Spring
In Spring Boot you can also set the active profile in application.properties , e.g. spring.profiles.active=production. A value set this way is replaced by...
Read more >
DBT - environment variables and running dbt - Stack Overflow
To access environment variables in your profiles.yml file, you replace the values for username and password with a call to the env_var macro ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found