# Demo deployment

The **demo deployment** offers a streamlined experience using a predefined raw
sample dataset. It provides an end-to-end workflow to deploy the
Google Cloud Cortex Framework Dataform pipelines for orchestration and
to initialize the corresponding BigQuery datasets with sample data.
Running `uv run cortex-demo` creates raw, data foundation, and data products
datasets for each selected source system (`sap` and `sfdc`), the
`cortex_demo_samples` dataset for SAP solution samples when deploying SAP, and
the `dataform_assertions` dataset during preflight checks (which
Dataform populates with assertion views when pipeline actions
run).

> [!CAUTION]
> **Caution:** Don't use the demo deployment for production environments. For production deployments, see [Cortex Framework production deployment](https://docs.cloud.google.com/cortex/docs/deployment.md.txt).

## Before you begin

Ensure you have completed the prerequisites outlined on the
[Prerequisites](https://docs.cloud.google.com/cortex/docs/prerequisites.md.txt) page, before continuing with
the demo deployment.

## Get the required Identity and Access Management roles

Obtain the required Identity and Access Management (IAM) permissions to deploy
Cortex Framework
content within the target Google Cloud project.

### Roles for target project


To get the permissions that
you need to deploy Cortex Framework,

ask your administrator to grant you the
following IAM roles on your target project:

- [BigQuery Job User](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.jobUser) (`roles/bigquery.jobUser`)
- [BigQuery Data Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataEditor) (`roles/bigquery.dataEditor`)
- [Dataform Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/dataform.md.txt#dataform.admin) (`roles/dataform.admin`)
- [Service Usage Consumer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageConsumer) (`roles/serviceusage.serviceUsageConsumer`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

> [!NOTE]
> **Note:** You can substitute Dataform Editor (`roles/dataform.editor`) for Dataform Admin (`roles/dataform.admin`) if the default Dataform repository `cortex-framework-demo` (or the repository specified with the `--repository-name` [parameter](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-demo.md.txt)) already exists before you run `uv run cortex-demo`.

To grant the requested roles to a user, run the following script:

```bash
# Grant BigQuery JobUser to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
        --role="roles/bigquery.jobUser"

# Grant BigQuery DataEditor to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
        --role="roles/bigquery.dataEditor"

# Grant Dataform Admin to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
        --role="roles/dataform.admin"

# Grant Service Usage Consumer to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
        --role="roles/serviceusage.serviceUsageConsumer"
```

Replace the following:

- `PROJECT_ID`: your target Google Cloud project ID, for example: `my-cortex-demo-project`.
- `USER_EMAIL`: the email address of the deploying user, for example: `analyst@example.com`.

## Optional: Service account IAM roles

The following roles are required only when you pass `--create-workflow-configs`
(which requires `--service-account`) to create one release configuration, five
scheduled Dataform workflow configurations (`hourly`, `daily`,
`weekly`, `monthly`, and `yearly` in UTC), and an immediate on-demand workflow
run. Providing a service account with `--create-workflow-configs` simplifies
post-deployment tasks by setting up the scheduling of the data pipelines. You
can also manually trigger any workflow configuration in Dataform on
the **Releases \& scheduling** tab using the three-dot menu.


To get the permissions that
you need to deploy the demo of Cortex Framework,

ask your administrator to grant you the
following IAM roles on your custom Dataform service account:

- [Service Account Token Creator](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountTokenCreator) (`roles/iam.serviceAccountTokenCreator`)
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

To create the service account and grant the necessary roles, run the following
script:

```bash
export PROJECT_ID=PROJECT_ID
export USER_EMAIL=USER_EMAIL
export SERVICE_ACCOUNT_NAME=cortex-dataform

# Create the service account
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME \
        --description="Service account for Cortex Dataform execution" \
        --display-name="Cortex Dataform Service Account" \
        --project=$PROJECT_ID

# Wait for the service account to propagate (IAM eventual consistency)
sleep 10

# Grant BigQuery DataEditor to the service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
        --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
        --role="roles/bigquery.dataEditor"

# Grant BigQuery jobUser to the service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
        --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
        --role="roles/bigquery.jobUser"

# Grant Dataform Editor to the service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
        --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
        --role="roles/dataform.editor"

# Grant the user Service Account Token Creator and Service Account User roles on the Cortex service account
gcloud iam service-accounts add-iam-policy-binding \
        $SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
        --member="user:$USER_EMAIL" \
        --role="roles/iam.serviceAccountTokenCreator" \
        --project=$PROJECT_ID

gcloud iam service-accounts add-iam-policy-binding \
        $SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
        --member="user:$USER_EMAIL" \
        --role="roles/iam.serviceAccountUser" \
        --project=$PROJECT_ID

PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")

# Note: If the following commands fail with a "serviceAccount:service-$PROJECT_NUMBER@..."
# not found error, the default Dataform service agent has not yet been provisioned
# for the project. Run these commands after the initial `uv run cortex-*` invocation.

# Grant the Dataform Service Account the Token Creator role on the Cortex service account
gcloud iam service-accounts add-iam-policy-binding \
        $SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
        --member="serviceAccount:service-$PROJECT_NUMBER@gcp-sa-dataform.iam.gserviceaccount.com" \
        --role="roles/iam.serviceAccountTokenCreator" \
        --project=$PROJECT_ID

# Grant the Dataform Service Account the Service Account User role on the Cortex service account
gcloud iam service-accounts add-iam-policy-binding \
        $SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \
        --member="serviceAccount:service-$PROJECT_NUMBER@gcp-sa-dataform.iam.gserviceaccount.com" \
        --role="roles/iam.serviceAccountUser" \
        --project=$PROJECT_ID
```

Replace the following:

- `PROJECT_ID`: your target Google Cloud project ID, for example: `my-cortex-demo-project`.
- `USER_EMAIL`: the email address of the deploying user, for example: `analyst@example.com`.

## Deployment

Follow these steps to create a virtual Python environment, synchronize the
dependencies, and trigger the data pipelines. Remember to use
the Cortex Framework `uv` scripts to build and push your data
assets to your Google Cloud project, transforming your local configurations
into a live, scalable data architecture. For more information, see the
[`uv` installation](https://docs.cloud.google.com/cortex/docs/prerequisites.md.txt#install-uv)
in the [Prerequisites](https://docs.cloud.google.com/cortex/docs/prerequisites.md.txt) section.

### Execute the demo deployment

Run the following command to trigger the deployment. This process performs the
following actions:

- Verify that all prerequisites are complete.
- Load sample data into a BigQuery dataset to serve as the raw layer for demonstration purposes.
- Build Dataform pipelines for processing the sample data through the Cortex Framework data layers.
- Create the Dataform repository and workspace, then sync the compiled artifacts with the repository.
- Optional: When you pass `--create-workflow-configs` together with `--service-account`, commit and push the workspace, create one release configuration (`<repository_name>-release`), create five scheduled Dataform workflow configurations (`hourly`, `daily`, `weekly`, `monthly`, and `yearly` in UTC), and trigger an immediate on-demand run.

> [!NOTE]
> **Note:** Public demo sample data is loaded from `gs://cortex-framework-public-<location>/demo-sample-data/rel710/...`, where `<location>` is the lowercased `--bigquery-location` value (default `US`). Make sure `--bigquery-location` matches a hosted demo location, and in restricted or VPC Service Controls environments, ensure read access to that public Cloud Storage bucket is permitted.

Running `uv run cortex-demo` collects anonymous telemetry (see
[Telemetry](https://docs.cloud.google.com/cortex/docs/telemetry.md.txt) to opt out). Run `uv run cortex-demo -h` or
see [CLI demo deployment](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-demo.md.txt) for all available
flags.

For demo deployment with default values (which deploys both SAP S/4HANA and
Salesforce sample datasets because `--sources` defaults to `all` and
`--sap-version` defaults to `s4`), run the following command (pass
`--sap-version ecc` for SAP ECC):

```bash
uv run cortex-demo --project-id=PROJECT_ID
```

Replace the following:

- `PROJECT_ID`: your target Google Cloud project ID, for example: `my-cortex-demo-project`.

To deploy only Salesforce demo datasets and data products, pass
`--sources sfdc`:

```bash
uv run cortex-demo --project-id=PROJECT_ID --sources sfdc
```

Replace the following:

- `PROJECT_ID`: your target Google Cloud project ID, for example: `my-cortex-demo-project`.

For demo deployment with a service account, five scheduled workflow
configurations, and an immediate on-demand run, run the following command:

> [!NOTE]
> **Note:** `--create-workflow-configs` requires `--service-account`. You can also pass `--service-account` without `--create-workflow-configs` to configure the repository's default execution service account without creating schedules.

```bash
export PROJECT_ID=PROJECT_ID
export SERVICE_ACCOUNT_NAME=cortex-dataform

uv run cortex-demo --project-id=$PROJECT_ID \
  --service-account="$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \
  --create-workflow-configs
```

Replace the following:

- `PROJECT_ID`: your target Google Cloud project ID, for example: `my-cortex-demo-project`.

> [!NOTE]
> **Note:** For detailed information on monitoring deployment progress, pipeline execution, and data quality, see [Cortex Framework Observability](https://docs.cloud.google.com/cortex/docs/observability.md.txt).

## Verification

After deployment completes, verify and run your demo pipelines:

1. Open [Dataform](https://console.cloud.google.com/bigquery/dataform), select the `cortex-framework-demo` repository, and open the `demo` workspace (click **Compiled graph** to inspect the compiled dependency graph).
2. Execute the Dataform actions using one of the following options:

   - **Option A --- Run manually (default deployment)** : Inside the `demo` workspace, click **Start execution** \> **Execute actions** \> **All actions** \> **Start execution** , and monitor progress on the **Workflow Execution Logs** tab.
   - **Option B --- Run using workflow schedules (when deployed with
     `--create-workflow-configs`)** : An initial run starts automatically during deployment. To trigger another run manually, open **Releases \&
     scheduling** , click the three-dot menu next to a workflow configuration, select **Start now** , and monitor progress on the **Workflow Execution
     Logs** tab.
3. Navigate to the [BigQuery console](https://console.cloud.google.com/bigquery) and
   click **Datasets** to view the created datasets and verify their schemas and
   sample rows. Depending on the `--sources` flag you selected, the created
   datasets include:

   - `cortex_demo_sap_s4_raw`: Sample raw SAP tables (when `--sources` is `all` or `sap` with `--sap-version s4`).
   - `cortex_demo_sap_s4_data_foundation`: CDC-processed SAP foundation tables.
   - `cortex_demo_sfdc_raw`: Sample raw Salesforce SObject tables (when `--sources` is `all` or `sfdc`).
   - `cortex_demo_sfdc_data_foundation`: Conformed Salesforce data foundation tables.
   - `cortex_demo_data_product`: Deployed SAP and Salesforce data products for consumption.
   - `cortex_demo_samples`: Sample consumption data products for SAP.
   - `dataform_assertions`: Compiled Dataform data quality assertion views (`uv run cortex-demo` creates the dataset during deployment preflight, and Dataform populates it with assertion views when pipeline actions run).

## Optional: Register demo data products in Knowledge Catalog

After you run your demo Dataform pipeline actions and verify that the
demo data product tables are materialized in BigQuery (in
`cortex_demo_data_product`, and in `cortex_demo_samples` when SAP is deployed),
you can register your demo data products in
[Knowledge Catalog](https://docs.cloud.google.com/cortex/docs/knowledge-catalog.md.txt) using
[`uv run cortex-create-kc-data-products`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-kc-data-products.md.txt).

Because `uv run cortex-demo` builds its configuration in memory and doesn't
write a `config/config.yaml` file, complete the following steps to enable the
Dataplex API, grant the required IAM roles, create a demo
configuration file, and register the demo data products.

### Enable the Dataplex API and grant required roles

Enable the Dataplex API (`dataplex.googleapis.com`) in your target
Google Cloud project:

```bash
gcloud services enable dataplex.googleapis.com \
    --project=PROJECT_ID
```

Replace `PROJECT_ID` with your target Google Cloud
project ID, such as `my-cortex-demo-project`.


To get the permissions that
you need to register and clean up demo data products in Knowledge Catalog,

ask your administrator to grant you the
following IAM roles on your target project:

- [Dataplex Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/dataplex.md.txt#dataplex.editor) (`roles/dataplex.editor`)
- [Dataplex Data Products Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/dataplex.md.txt#dataplex.dataProductsEditor) (`roles/dataplex.dataProductsEditor`)
- [Dataplex Entry and EntryLink Owner](https://docs.cloud.google.com/iam/docs/roles-permissions/dataplex.md.txt#dataplex.entryOwner) (`roles/dataplex.entryOwner`)
- [BigQuery Metadata Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.metadataViewer) (`roles/bigquery.metadataViewer`)
- [BigQuery Data Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataViewer) (`roles/bigquery.dataViewer`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

Grant these roles to the principal running
`uv run cortex-create-kc-data-products`:

```bash
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/dataplex.editor"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/dataplex.dataProductsEditor"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/dataplex.entryOwner"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/bigquery.metadataViewer"
gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_EMAIL" \
    --role="roles/bigquery.dataViewer"
```

Replace the following:

- `PROJECT_ID`: Your Google Cloud project ID where you register demo Knowledge Catalog data products (or where your demo datasets are hosted), such as `my-cortex-demo-project`.
- `USER_EMAIL`: The email address of the principal running `uv run cortex-create-kc-data-products`, such as `dana@example.com`.

> [!NOTE]
> **Note:** If you centralize Knowledge Catalog data products in a separate governance project using `--kc-project-id`, enable `dataplex.googleapis.com` and grant the Knowledge Catalog roles on that governance project while keeping the BigQuery viewer roles on the project hosting your demo datasets.

### Create a demo configuration file

Create a demo configuration file (`config/config-demo.yaml`) from the
`config/config.yaml.example` template so `uv run cortex-create-kc-data-products`
can discover your demo datasets without overwriting an existing
`config/config.yaml` file. Update the project ID attributes,
BigQuery dataset IDs, and Dataform repository and
workspace settings in `config/config-demo.yaml` to match the default parameters
of `uv run cortex-demo`.

Expand the following section for step-by-step instructions to copy the template
and edit each required section:

#### Create and update the
`config/config-demo.yaml` file for default demo parameters

Follow these steps from the root directory of your cloned
Cortex Framework repository to create
`config/config-demo.yaml` and align it with the default parameters
used by `uv run cortex-demo` (`--sources all`,
`--sap-version s4`, `--bigquery-location US`,
`--dataform-region us-central1`,
`--repository-name cortex-framework-demo`, and
`--workspace-name demo`).

1. Copy the example configuration template to a dedicated demo file:

   ```bash
   cp config/config.yaml.example config/config-demo.yaml
   ```
2. Open `config/config-demo.yaml` and update all active project
   ID attributes to your target Google Cloud project ID
   (`PROJECT_ID`, matching the
   `--project-id` flag):

   - `buildEnvironment.buildProjectId`: replace `YOUR_BUILD_PROJECT_ID` with `PROJECT_ID`.
   - `data.datasets[].projectId`: replace `YOUR_SOURCE_PROJECT_ID` (on `sap_raw` and `sfdc_raw`) and `YOUR_TARGET_PROJECT_ID` (on `sap_foundation`, `sfdc_foundation`, `product_target`, `samples_target`, and `cortex_v6_compatibility_target`) with `PROJECT_ID`.
   - `deployment.targets[].targetSettings.repositoryProjectId`: replace `YOUR_REPO_PROJECT_ID` with `PROJECT_ID`.

   Leave the placeholder project IDs under the disabled
   `data.modules.catalogs` entries (`enabled: false`)
   unchanged unless you enable those external catalogs.

   ```yaml
   buildEnvironment:
     buildProjectId: PROJECT_ID
   ```

   Replace `PROJECT_ID` with your target
   Google Cloud project ID, such as
   `my-cortex-demo-project`.
3. Under `data.datasets`, update the `datasetId`
   values from the template defaults to match the default
   `uv run cortex-demo` datasets:

   - `sap_raw`: change `cortex_sap_raw` to `cortex_demo_sap_s4_raw` (default `--source-sap-raw-dataset-id`).
   - `sap_foundation`: change `cortex7_sap_data_foundation` to `cortex_demo_sap_s4_data_foundation` (default `--target-sap-foundation-dataset-id`).
   - `sfdc_raw`: change `cortex_sfdc_raw` to `cortex_demo_sfdc_raw` (default `--source-sfdc-raw-dataset-id`).
   - `sfdc_foundation`: change `cortex7_sfdc_data_foundation` to `cortex_demo_sfdc_data_foundation` (default `--target-sfdc-foundation-dataset-id`).
   - `product_target`: change `cortex7_data_products` to `cortex_demo_data_product` (default `--target-dp-dataset-id`; note singular `product`).
   - `samples_target`: change `cortex7_samples` to `cortex_demo_samples` (default `--target-samples-dataset-id`).

   Keep the `cortex_v6_compatibility_target` entry in
   `data.datasets` so configuration validation succeeds for the
   disabled compatibility modules (all `cortex_v6_compatibility`
   entries remain `enabled: false` and
   `syncToKc: false`):

   ```yaml
   datasets:
     - id: sap_raw
       projectId: PROJECT_ID
       datasetId: cortex_demo_sap_s4_raw
     - id: sap_foundation
       projectId: PROJECT_ID
       datasetId: cortex_demo_sap_s4_data_foundation
     - id: sfdc_raw
       projectId: PROJECT_ID
       datasetId: cortex_demo_sfdc_raw
     - id: sfdc_foundation
       projectId: PROJECT_ID
       datasetId: cortex_demo_sfdc_data_foundation
     - id: product_target
       projectId: PROJECT_ID
       datasetId: cortex_demo_data_product
     - id: samples_target
       projectId: PROJECT_ID
       datasetId: cortex_demo_samples
     - id: cortex_v6_compatibility_target
       projectId: PROJECT_ID
       datasetId: cortex_v6_compatibility
   ```
4. Under `deployment.targets`, update the
   Dataform target settings to match the default
   `uv run cortex-demo` parameters:

   - `repositoryProjectId`: replace `YOUR_REPO_PROJECT_ID` with `PROJECT_ID`.
   - `repositoryRegion`: keep `us-central1` (default `--dataform-region`), or update it to match a custom region.
   - `repositoryName`: change `cortex-repository` to `cortex-framework-demo` (default `--repository-name`).
   - `workspaceName`: change `dev` to `demo` (default `--workspace-name`).

   ```yaml
   deployment:
     targets:
       - type: dataform
         enabled: true
         targetSettings:
           repositoryProjectId: PROJECT_ID
           repositoryRegion: us-central1
           repositoryName: cortex-framework-demo
           workspaceName: demo
   ```

   If you passed `--service-account` to
   `uv run cortex-demo`, uncomment `serviceAccount`
   under `targetSettings` and set it to your service account email
   address.
5. Optional: Adjust `config/config-demo.yaml` if you want to
   register the SAP solution samples or if you overrode default
   `uv run cortex-demo` flags:

   - **Include SAP solution samples.** `uv run cortex-demo` deploys `sap_sales_performance` and `sap_supplier_spend_analysis` into `cortex_demo_samples` when SAP is included, while `config/config.yaml.example` leaves both set to `enabled: false`. Set `enabled: true` on both entries under `data.modules.products` to register them.
   - **Match a custom `--bigquery-location`.** Update `data.bigQueryLocation` to match the location you passed to `uv run cortex-demo` (default `US`).
   - **Match a custom `--sources` value.** If you deployed with `--sources sfdc`, set `enabled: false` (or `syncToKc: false`) on the SAP entries under `data.modules.products` so empty data products aren't registered. If you deployed with `--sources sap`, disable or set `syncToKc: false` on the Salesforce entries.
   - **Match `--sap-version ecc`.** Update `sap_raw` and `sap_foundation` to `cortex_demo_sap_ecc_raw` and `cortex_demo_sap_ecc_data_foundation`, and set `moduleSettings.sapVersion: ecc` on `erp`. Enable `sap_general_ledger_items` and `sap_inventory_and_special_stocks`, disable `sap_universal_journal`, and switch the version-specific `dependencyBindings` on `sap_accounts_receivable_insights` and `sap_financial_statements` as shown in the inline comments in `config/config.yaml.example`.
   - **Match custom Dataform flags.** If you overrode `--dataform-region`, `--repository-name`, or `--workspace-name`, update `repositoryRegion`, `repositoryName`, and `workspaceName` under `deployment.targets` to match.

### Register and verify demo data products

1. Synchronize your materialized demo data products with
   Knowledge Catalog:

   ```bash
   uv run cortex-create-kc-data-products \
       --config config/config-demo.yaml \
       --owner-email OWNER_EMAIL
   ```

   Replace `OWNER_EMAIL` with the email address assigned
   as the data product owner in Knowledge Catalog, such
   as `dana@example.com`.

   To register all demo data products in a separate governance project instead
   of the project hosting your demo BigQuery datasets, add
   `--kc-project-id KC_PROJECT_ID`, where
   `KC_PROJECT_ID` is the governance project ID.
2. In the Google Cloud console, go to the Knowledge Catalog
   **Data products** page:

   [Go to Data products](https://console.cloud.google.com/dataplex/govern/data-products)
3. On the Google Cloud console toolbar, click the resource selector, and then
   select your target project.

4. Click a registered demo data product to inspect its business description,
   governance labels (including `cortex_framework_created: "true"`), and linked
   BigQuery tables from `cortex_demo_data_product` (and
   `cortex_demo_samples` if enabled).

For more information about governance labels, reconciliation behavior, and
production automation, see
[Knowledge Catalog integration](https://docs.cloud.google.com/cortex/docs/knowledge-catalog.md.txt)
and the
[`uv run cortex-create-kc-data-products` CLI reference](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-kc-data-products.md.txt).

## Cleanup demo deployment resources

After a successful demo deployment, you can remove the used Google Cloud
resources to avoid ongoing charges. The following script deletes the created
BigQuery datasets, the Dataform workspace, any workflow
and release configurations, and the Dataform repository. If found, the
script also prompts you to optionally delete the `cortex-dataform` service
account. If you also registered demo data products in
Knowledge Catalog, remove them by following
[Optional: Clean up Knowledge Catalog demo data
products](https://docs.cloud.google.com/cortex/docs/demo-deployment#cleanup-knowledge-catalog).

Expand the following section to view the demo deployment cleanup script:

#### Demo deployment cleanup script

Before running the script, replace `PROJECT_ID` with
your target Google Cloud project ID, such as
`my-cortex-demo-project`. Also update any variable at the top of
the script whose default you overrode with `uv run cortex-demo`
flags (such as `--sap-version`, `--dataform-region`,
dataset IDs, `--repository-name`, `--workspace-name`, or
`--service-account`):

```bash
#!/bin/bash

# Define variables using names from uv-run-cortex-demo.md
PROJECT_ID="PROJECT_ID"
SAP_VERSION="s4"

DATAFORM_REGION="us-central1"
SOURCE_SAP_RAW_DATASET_ID="cortex_demo_sap_s4_raw"
TARGET_SAP_FOUNDATION_DATASET_ID="cortex_demo_sap_s4_data_foundation"
if [[ "$SAP_VERSION" == "ecc" ]]; then
  SOURCE_SAP_RAW_DATASET_ID="cortex_demo_sap_ecc_raw"
  TARGET_SAP_FOUNDATION_DATASET_ID="cortex_demo_sap_ecc_data_foundation"
fi
SOURCE_SFDC_RAW_DATASET_ID="cortex_demo_sfdc_raw"
TARGET_SFDC_FOUNDATION_DATASET_ID="cortex_demo_sfdc_data_foundation"
TARGET_DP_DATASET_ID="cortex_demo_data_product"
TARGET_SAMPLES_DATASET_ID="cortex_demo_samples"
ASSERTIONS_DATASET_ID="dataform_assertions"
REPOSITORY_NAME="cortex-framework-demo"
WORKSPACE_NAME="demo"
SERVICE_ACCOUNT_NAME="cortex-dataform"


# Color codes for formatting status output
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Helper function to delete a resource and report status
delete_resource() {
    local label=$1
    local url=$2
    local resource_type=$3
    
    echo -n "${label}... "
    
    local temp_file=$(mktemp)
    local code=$(curl -s -o "${temp_file}" -w "%{http_code}" -X DELETE \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        "${url}")
        
    if [ "$code" -eq 200 ] || [ "$code" -eq 204 ]; then
        echo -e "${GREEN}ok${NC}"
    elif [ "$code" -eq 404 ]; then
        echo -e "${YELLOW}skipped, ${resource_type} not found${NC}"
    else
        echo -e "${RED}failed (HTTP ${code})${NC}"
        if [ -s "${temp_file}" ]; then
            echo "  Error details:"
            sed 's/^/    /' "${temp_file}"
        fi
    fi
    rm -f "${temp_file}"
}

echo "Deleting BigQuery datasets..."
for DATASET_ID in "${SOURCE_SAP_RAW_DATASET_ID}" \
                  "${TARGET_SAP_FOUNDATION_DATASET_ID}" \
                  "${SOURCE_SFDC_RAW_DATASET_ID}" \
                  "${TARGET_SFDC_FOUNDATION_DATASET_ID}" \
                  "${TARGET_DP_DATASET_ID}" \
                  "${TARGET_SAMPLES_DATASET_ID}" \
                  "${ASSERTIONS_DATASET_ID}"; do
    echo "deleting ${PROJECT_ID}:${DATASET_ID}"
    bq rm -r -f "${PROJECT_ID}:${DATASET_ID}"
done

ACCESS_TOKEN=$(gcloud auth print-access-token)
delete_resource "Deleting Dataform workspace ${WORKSPACE_NAME}" \
    "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}/workspaces/${WORKSPACE_NAME}" \
    "workspace"

echo "Deleting Dataform workflow configurations..."
WORKFLOW_CONFIGS_JSON=$(curl -s -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}/workflowConfigs")

WORKFLOW_CONFIGS=$(echo "${WORKFLOW_CONFIGS_JSON}" | grep '"name":' | sed -E 's/.*"name": "([^"]+)".*/\1/')

if [ -z "${WORKFLOW_CONFIGS}" ]; then
    echo -e "  No workflow configurations found. ${YELLOW}skipped${NC}"
else
    for config in ${WORKFLOW_CONFIGS}; do
        delete_resource "  Deleting workflow config: ${config##*/}" \
            "https://dataform.googleapis.com/v1beta1/${config}" \
            "workflow config"
    done
fi

echo "Deleting Dataform release configurations..."
RELEASE_CONFIGS_JSON=$(curl -s -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}/releaseConfigs")

RELEASE_CONFIGS=$(echo "${RELEASE_CONFIGS_JSON}" | grep '"name":' | sed -E 's/.*"name": "([^"]+)".*/\1/')

if [ -z "${RELEASE_CONFIGS}" ]; then
    echo -e "  No release configurations found. ${YELLOW}skipped${NC}"
else
    for config in ${RELEASE_CONFIGS}; do
        delete_resource "  Deleting release config: ${config##*/}" \
            "https://dataform.googleapis.com/v1beta1/${config}" \
            "release config"
    done
fi

delete_resource "Deleting Dataform repository ${REPOSITORY_NAME}" \
    "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}?force=true" \
    "repository"

if gcloud iam service-accounts describe "${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" --project="${PROJECT_ID}" >/dev/null 2>&1; then
    read -p "Do you want to delete the service account ${SERVICE_ACCOUNT_NAME}? (y/N): " -r
    if [[ "$REPLY" =~ ^[Yy]$ ]]; then
        echo -n "Deleting service account ${SERVICE_ACCOUNT_NAME}... "
        ERROR_MSG=$(gcloud iam service-accounts delete "${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" --project="${PROJECT_ID}" --quiet 2>&1)
        EXIT_CODE=$?
        if [ ${EXIT_CODE} -eq 0 ]; then
            echo -e "${GREEN}ok${NC}"
        else
            echo -e "${RED}failed${NC}"
            echo "  Error details:"
            echo "${ERROR_MSG}" | sed 's/^/    /'
        fi
    else
        echo -e "Deleting service account ${SERVICE_ACCOUNT_NAME}... ${YELLOW}skipped (user cancelled)${NC}"
    fi
else
    echo -e "Deleting service account ${SERVICE_ACCOUNT_NAME}... ${YELLOW}skipped, service account not found${NC}"
fi

echo "Cortex Framework demo deployment cleanup complete."
```

## Optional: Clean up Knowledge Catalog demo data products

If you registered demo data products in
Knowledge Catalog, run the following standalone script
to delete all Cortex Framework-managed data products and their
linked data assets. The script filters for data products carrying the
`cortex_framework_created: "true"` (or legacy
`cortex-framework-created: "true"`) ownership label so customer-managed catalog
entries aren't modified, and prompts for confirmation before deleting any
resources.

Run this script with a principal that has the
Knowledge Catalog roles granted in
[Enable the Dataplex API and grant required roles](https://docs.cloud.google.com/cortex/docs/demo-deployment.md.txt#kc-prerequisites),
including `roles/dataplex.dataProductsEditor`. You can run this script before
or after deleting your demo BigQuery datasets.

Expand the following section to view the standalone
Knowledge Catalog cleanup script:

#### Knowledge Catalog demo data
products cleanup script

Run the following cleanup script after adjusting its configuration
values:

```bash
#!/bin/bash

PROJECT_ID="PROJECT_ID"
BIGQUERY_LOCATION="US"

# Knowledge Catalog locations are lowercased (for example, "US" becomes "us").
KC_LOCATION=$(echo "${BIGQUERY_LOCATION}" | tr '[:upper:]' '[:lower:]')

# Color codes for formatting status output
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

KC_ERR_FILE=$(mktemp)
trap 'rm -f "${KC_ERR_FILE}"' EXIT

KC_DATA_PRODUCTS=$(gcloud dataplex data-products list \
    --project="${PROJECT_ID}" \
    --location="${KC_LOCATION}" \
    --filter='labels.cortex_framework_created="true" OR labels.cortex-framework-created="true"' \
    --format="value(name)" \
    --quiet 2>"${KC_ERR_FILE}")
KC_LIST_EXIT_CODE=$?

if [ ${KC_LIST_EXIT_CODE} -ne 0 ]; then
    if grep -qE "SERVICE_DISABLED|API \[dataplex\.googleapis\.com\] not enabled|has not been used in project" "${KC_ERR_FILE}"; then
        echo -e "Deleting Knowledge Catalog data products... ${YELLOW}skipped, Dataplex API not enabled${NC}"
    else
        echo -e "Deleting Knowledge Catalog data products... ${RED}failed to list data products${NC}"
        if [ -s "${KC_ERR_FILE}" ]; then
            echo "  Error details:"
            sed 's/^/    /' "${KC_ERR_FILE}"
        fi
        exit 1
    fi
elif [ -z "${KC_DATA_PRODUCTS}" ]; then
    echo -e "Deleting Knowledge Catalog data products... ${YELLOW}skipped, no Cortex Framework data products found${NC}"
else
    echo "Found Cortex Framework Knowledge Catalog data products in ${PROJECT_ID} (${KC_LOCATION}):"
    while IFS= read -r DP_NAME; do
        [ -n "${DP_NAME}" ] && echo "  - ${DP_NAME##*/}"
    done <<< "${KC_DATA_PRODUCTS}"

    read -p "Do you want to delete these Knowledge Catalog data products and their linked assets? (y/N): " -r
    if [[ "$REPLY" =~ ^[Yy]$ ]]; then
        while IFS= read -r DP_NAME; do
            [ -z "${DP_NAME}" ] && continue
            DP_ID="${DP_NAME##*/}"

            # Remove linked data assets before deleting the data product
            ASSET_LIST_ERR=$(mktemp)
            DATA_ASSETS=$(gcloud dataplex data-products data-assets list \
                --data-product="${DP_ID}" \
                --project="${PROJECT_ID}" \
                --location="${KC_LOCATION}" \
                --format="value(name)" \
                --quiet </dev/null 2>"${ASSET_LIST_ERR}")
            ASSET_LIST_EXIT=$?
            if [ ${ASSET_LIST_EXIT} -ne 0 ]; then
                echo -e "Listing data assets for ${DP_ID}... ${RED}failed${NC}"
                if [ -s "${ASSET_LIST_ERR}" ]; then
                    echo "  Error details:"
                    sed 's/^/    /' "${ASSET_LIST_ERR}"
                fi
                rm -f "${ASSET_LIST_ERR}"
                continue
            fi
            rm -f "${ASSET_LIST_ERR}"

            ASSET_DELETE_FAILED=0
            if [ -n "${DATA_ASSETS}" ]; then
                while IFS= read -r ASSET_NAME; do
                    [ -z "${ASSET_NAME}" ] && continue
                    ASSET_ID="${ASSET_NAME##*/}"
                    echo -n "  Deleting data asset ${ASSET_ID} from ${DP_ID}... "
                    ERROR_MSG=$(gcloud dataplex data-products data-assets delete "${ASSET_ID}" \
                        --data-product="${DP_ID}" \
                        --project="${PROJECT_ID}" \
                        --location="${KC_LOCATION}" \
                        --quiet </dev/null 2>&1)
                    if [ $? -eq 0 ]; then
                        echo -e "${GREEN}ok${NC}"
                    else
                        ASSET_DELETE_FAILED=1
                        echo -e "${RED}failed${NC}"
                        echo "    Error details:"
                        echo "${ERROR_MSG}" | sed 's/^/      /'
                    fi
                done <<< "${DATA_ASSETS}"
            fi

            if [ ${ASSET_DELETE_FAILED} -ne 0 ]; then
                echo -e "Deleting Knowledge Catalog data product ${DP_ID}... ${YELLOW}skipped, failed to remove all linked assets${NC}"
                continue
            fi

            echo -n "Deleting Knowledge Catalog data product ${DP_ID}... "
            ERROR_MSG=$(gcloud dataplex data-products delete "${DP_ID}" \
                --project="${PROJECT_ID}" \
                --location="${KC_LOCATION}" \
                --quiet </dev/null 2>&1)
            if [ $? -eq 0 ]; then
                echo -e "${GREEN}ok${NC}"
            else
                echo -e "${RED}failed${NC}"
                echo "  Error details:"
                echo "${ERROR_MSG}" | sed 's/^/    /'
            fi
        done <<< "${KC_DATA_PRODUCTS}"
    else
        echo -e "Deleting Knowledge Catalog data products... ${YELLOW}skipped (user cancelled)${NC}"
    fi
fi

echo "Cortex Framework Knowledge Catalog demo cleanup complete."
```

Replace the following:

- `PROJECT_ID`: The Google Cloud project ID where your demo Knowledge Catalog data products are registered (your demo project ID, or your governance project ID if you passed `--kc-project-id`), such as `my-cortex-demo-project`.

If you used a non-default location in `config/config-demo.yaml`,
also update `BIGQUERY_LOCATION` at the top of the script.

If you created `config/config-demo.yaml` for demo registration, you can also
remove that local configuration file by running
`rm -f config/config-demo.yaml`.

## Next steps

- **Follow the [Production deployment](https://docs.cloud.google.com/cortex/docs/deployment.md.txt)** to learn how to deploy Cortex Framework in production environments.
- **Read about
  [Source system integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/overview.md.txt)** to learn how to connect your production systems.