Environment variables for dbt (launched)

Buck Ryan · Friday Demos · June 14, 2024 · 5:22

Environment variables for dbt. We need to be able to support in-production dbt environments, and that means coupling with environment variables for tight dynamic schema support

Transcript

This transcript is auto-generated. Names and product terms may be wrong.

  1. I've got something for DBT to demo let me just find the right window as usual okay so um what I'm going to show is a change to the way that DBT environments work so if you remember some of the demos from a few weeks ago when you are in a branch you would pop this pop down open and it would show you options to type in a schema name and sometimes a database name where this is all going is um instead of doing that for each branch that you open uh environments are going to be long lived um so when you like create a new DBT connection um you enter the target schema that's like the bare minimum you need to make an environment and

  2. it'll go down there after you make it it'll show up as this production default environment um and then uh so when you're in Branch mode you can just select from existing environments you've already made or you can make a new one and um the reason for all this is that there's a lot more to environments than just a schema and so now when you go to edit an environment you're presented with this new dialogue um in particular this target name is new and it's something that a a customer needed in the past most of the time people don't need this but um it affects the way that the DBT code gets compiled and uh in some cases you need it for things to work correctly

  3. and then variables is the bigger thing um this has come up somewhere between five and 10 times where customers need or want some sort of environment variable um usually what we've seen is it it has to do with they're using environment variables to determine like which database models are going to go into um and one case a customer needed a variable that was like a secret in order to pull down git uh dependencies uh like DBT dependencies so you can do all of that um now if you need to store something secret you name it dbtm secret this prefix uh here I'm just matching the way that DBT Cloud Works um DBT Cloud does the same thing where you use that prefix to indicate that

  4. it's a secret Val value um and you know you can add remove Etc all of these things so um I think that's everything I wanted to cover buck when when you name the variable whether it's DBT a or DBT and secretor a like in your code do you refer to it as a or do you refer to it as DBT a uh as it it just gets passed through into the envir environment variables that are used when you run DBT commands so this does not get manipulated it's just DBT a and the reason for the requiring the prefix for me there's like I'm mimicking what DBT cloud is doing but also from a security point of view it prevents you from like specifying that you're

  5. going to override the path or something like that Goa so if you're in your DBT repository or my DBT repository it's sort of a stand standard that I only use environment variables that are prefixed with DBT yeah um it's common and especially if you're using DBT Cloud already you have to do it because those are the way that they do it um uh so yeah it's it's common and a lot of the docs sort of give dcore as a as an example yeah I think it's it's a little bit of a wonky set up but I think it was a completely rational choice to just follow what they do um different question do you think this I know we've run into people who do like

  6. some pretty wonky stuff with like configuring the names of schemas and so forth when they run DBT do you think we have all of those cases covered by this or are there still some cases where people can do weird stuff there this would cover the last of all the cases that I've seen and I'm not really sure what else you could do uh that we wouldn't be covered at this point because uh the way that we run the dbd code is going to like perfectly match um the way that they're running it to determine so like the way that we execute the code is is has been identical and now all that's missing is sort of these runtime environment variables and environment variables are as

  7. far as I know the only configuration you can provide at runtime so yeah all the should be the same therefore if you're doing crazy logic with it that's on you we we'll still get the same outputs because we have the same inputs yeah cool thanks and uh I'm gonna need somebody to stop sharing from me again thanks