Calling the SECRETS

Hi All,
I’m building a python model in dbt and my dbt is connected to Snowflake. I’m following this DBT documentation and this Snowflake documentation

  • I’ve created external access integration in Snowflake called metabase_access_integration. When I run my model in dbt, I saw that dbt can access this external access integration
  • I’ve created secret in Snowflake called metabase_api_password. However, I found Object 'METABASE_API_PASSWORD' does not exist or not authorized. . I made that secret in multiple schemas but dbt is still not able to find that secret.

I took another approach by storing the secret in the environment variables. I stored in DBT_ENV_SECRET_METABASE. However, I cannot call it both in python model and in SQL model.

Can anybody help me with this?

Can you post the code you’ve tried to use, both when accessing the variable through the Snowflake secret and using environment variables?

Sure,

Approach 1
Here is the code I’m using to call the Snowflake secret

    dbt.config(
        materialized="table",
        schema='source',
        packages = ['requests','pandas'],
        external_access_integrations=["metabase_access_integration"],
        secrets={"cred": "metabase_api_password"},
        
    )

    import _snowflake

    return session.create_dataframe ((('test_model_1'),('test_model_2')))

returns

SQL compilation error:
  Object 'METABASE_API_PASSWORD' does not exist or not authorized.
  compiled code at 

Approach 2

I stored the dbt_ENV_SECRET_METABASE (see screenshot)

Here is the code I’m using to call the environment variable

def model(dbt, session):
    dbt.config(
        materialized="table",
        schema='source',
        packages = ['requests','pandas'],
        external_access_integrations=["metabase_access_integration"],
        
    )

    import _snowflake
    import os

    metabase_secret = os.getenv("DBT_ENV_SECRET_METABASE")
    

    return session.create_dataframe (((metabase_secret),(metabase_secret)))

The model was successfully built, but when I call the table, I found it ‘null’ while I expect I got the value of Metabase_secret (just for testing of course)

The secret that I stored in Snowflake was created under role_reporting_pii

And I’m using the same role when I’m developing the model in dbt