[CT-369] [Feature] Use variables declared in dbt_project.yml file in the file
See original GitHub issueIs there an existing feature request for this?
- I have searched the existing issues
Describe the Feature
When I declare a variable in a dbt_project file, I sometimes need to use it in the same file. For example:
vars:
special_schema: "my_special_schema"
models:
my_staging_models:
staging:
+materialized: view
common:
+enabled: true
+schema: "{{ var('my_special_schema') }}"
special_schema is declared in the project-level vars because I need it in several places. I also need to specify this schema as the schema for some models. Currently when I do the above, I get an error:
Compilation Error Could not render {{ var(‘my_special_schema’) }}: Required var ‘my_special_schema’ not found in config: Vars supplied to <Configuration> = {}
Describe alternatives you’ve considered
Currently, I am adding a config block to every model to specify the schema, and that works, but with many models, it gets very repetitive. It would be nice to specify the schema once (using a variable), in the project file, and not have to do it again.
I suppose I could also include --vars "my_special_schema: some_schema" when running DBT, but for ease of use by others, I’d prefer to use the vars: block in the project file. We have many variables, and there are a few more I’d like to use in this way. Passing them all from the CLI makes for messier scripts.
Who will this benefit?
Everyone who wants to make use of variables in the project file, for variables that are declared in the project file.
Are you interested in contributing this feature?
Yes, but I’m not sure I have the necessary skills or time.
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:5 (3 by maintainers)
Top Related StackOverflow Question
Having the vars in a separate file as one option could make life easier for some devops people as they could move a project around between environments and instead of modifying the vars in the project file, they could just swap different vars files in different environments and leave everything else untouched.
Although we are closing this issue as stale, it’s not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.