Area: Best Practices
Sub-Area: dbt Core Ingestion Configuration
Applies to: OSS + Cloud
Issue
You ingest dbt Core across more than one warehouse account, environment, or dbt project. You need dbt entities with stable, unique URNs, and you need dbt models to link to the matching warehouse tables as siblings and in lineage. A dbt recipe has two instance settings, and they do different jobs. If you mix them up, dbt nodes do not link to the warehouse tables, or two projects or environments write to the same dbt URNs.
You Might Be Asking
- What should I use as the
platform_instancein my dbt Core recipe? - Which dbt setting has to match the
platform_instancein my Snowflake (or other warehouse) recipe? - How do I keep dbt URNs separate across dev, staging, and prod, or across several dbt projects?
- What happens if I change
platform_instancebetween ingestion runs?
Solution
- Know what each setting controls.
The dbt source has two instance settings:
-
platform_instancescopes the dbt side URNs only (urn:li:dataPlatform:dbt). These include dbt models, sources, seeds, assertions, and exposures. -
target_platform_instancescopes the warehouse side URNs. dbt uses these URNs to link its nodes to the warehouse tables as siblings and in lineage.
The dbt source has no platform_instance_map setting. The recipe rejects unknown keys, so a recipe with platform_instance_map fails validation.
- Match
target_platform_instanceandenvto your warehouse recipe.
If your warehouse recipe sets a platform_instance, set target_platform_instance in the dbt recipe to the same value. dbt builds the warehouse URNs from target_platform, target_platform_instance, and env. So env must also match the warehouse recipe's env. Both default to PROD. The dbt platform_instance does not need to match the warehouse.
# Snowflake recipe
source:
type: snowflake
config:
account_id: "<your-snowflake-account>"
platform_instance: "snowflake_prod"
# dbt Core recipe
source:
type: dbt
config:
manifest_path: /path/to/target/manifest.json
catalog_path: /path/to/target/catalog.json
target_platform: snowflake
target_platform_instance: "snowflake_prod" # same as platform_instance in the Snowflake recipe
platform_instance: "analytics" # the dbt project name
See the dbt source documentation for every config option.
- Choose the dbt
platform_instance.
If you ingest more than one dbt project, set platform_instance in each recipe to that project's name (the name: in its dbt_project.yml). That keeps the dbt URNs of different projects distinct, including models from a package that several projects install. If you ingest only one dbt project, you can leave platform_instance unset.
- Use one recipe per warehouse account or environment.
When the same dbt project runs against separate warehouse accounts (for example a prod and a dev Snowflake account), write one dbt recipe per account. In each recipe, set target_platform_instance and env to the values of that account's warehouse recipe. Each recipe also needs distinct dbt URNs, so the two recipes must differ in env or in platform_instance.
# dbt recipe for the production account
source:
type: dbt
config:
manifest_path: /path/to/prod/manifest.json
catalog_path: /path/to/prod/catalog.json
target_platform: snowflake
target_platform_instance: "snowflake_prod" # Snowflake prod recipe's platform_instance
platform_instance: "analytics"
env: PROD # Snowflake prod recipe's env
# dbt recipe for the development account
source:
type: dbt
config:
manifest_path: /path/to/dev/manifest.json
catalog_path: /path/to/dev/catalog.json
target_platform: snowflake
target_platform_instance: "snowflake_dev" # Snowflake dev recipe's platform_instance
platform_instance: "analytics"
env: DEV # Snowflake dev recipe's env
- Use stable, readable values. Don't use hashes.
A platform instance becomes part of every URN, and URNs can't be renamed. If you hash connection details into the value, any change to those details gives you a new value and a new set of URNs. A hash also doesn't tell you which environment an entity belongs to. Pick short names that won't change, as described in Working With Platform Instances.
- Pick the value before the first ingestion.
If you change platform_instance later, every dbt URN of the project changes. The next run creates new dbt entities. Descriptions, tags, glossary terms, owners, and documentation that people added in DataHub stay on the old entities and do not move to the new ones. The warehouse tables don't change, because their URNs don't include the dbt platform instance.
If old dbt entities are still there after the first run with the new value, remove them by deleting the old dbt platform instance with --recursive. Run it with --dry-run first. A dry run lists the entities and deletes nothing.
datahub delete --urn 'urn:li:dataPlatformInstance:(urn:li:dataPlatform:dbt,<old-platform-instance>)' --recursive --dry-run
Then run the same command without --dry-run. The command soft deletes by default. datahub delete has no --platform-instance option. See Removing Metadata from DataHub.
Additional Notes
dbt Core can ingest several projects from one recipe if you set manifest_path to a glob pattern (for example /path/to/dbt-artifacts/*/manifest.json). In that mode each project's platform_instance is its manifest's project name, and you can't set platform_instance, catalog_path, sources_path, or git_info in the recipe. target_platform_instance is still set once and shared by every project. If you set each project's platform_instance to its project name in one-recipe-per-project setups, a later move to a glob recipe keeps the same dataset and assertion URNs. Glob support needs a recent CLI, so upgrade to the latest release to use it.
A dbt Cloud recipe ingests one project and uses the same rule: set platform_instance to the dbt project name when you ingest more than one project.