How to pass variable in Airflow to dbt_projec.yml file

The problem I’m having

After deploying dbt models to Airflow, I don’t know how to pass the variable value from airflow to dbt.

The context of why I’m trying to do this

I’m trying to do different grants based on what env I’m deploying to. I want to assign to the same role if deploying to dev or test env, and don’t assign any roles if deploying to prod.

Some example code or error messages

This is what I have in the dbt_project.yml file.

+grants:
    select: "{{ ['dev_and_test_role'] if env_var('DBT_ENVIRONMENT') in ['dev', 'test'] else []}}"

But I don’t know where do I set the DBT_ENVIRONMENT value in airflow so that it can be passed down to the yml file.

For me, the easiest way to set environment variables is by creating a .env file in your projects folder like this:

# your .env file
export DBT_ENVIRONMENT="dev"

then run in your terminal

source .env

You can add ‘source .env’ to your bashrc or zshrc (depending on you shell) to run it automatically

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.