This document covers import flows, brownfield adoption, and common provider issues.
If groups, tag policies, tag assignments, or FGAC policies already exist in Databricks, import them so Terraform can manage them without already exists errors:
make import ENV=account # import account groups + tag policies into module.account
make import # import env-scoped governance + workspace-local resources for ENV=dev
make import ENV=prod # import env-scoped governance + workspace-local resources for ENV=prod
cd envs/account && ../../scripts/import_existing.sh --groups-only --dry-run
cd envs/account && ../../scripts/import_existing.sh --tags-only --dry-run # tag policies live in account
cd envs/dev/data_access && ../../../scripts/import_existing.sh --fgac-only
cd envs/dev/data_access && ../../../scripts/import_existing.sh --tag-assignments-onlyFor environments with existing ABAC infrastructure:
make generate
vi envs/dev/generated/masking_functions.sql
vi envs/dev/generated/abac.auto.tfvars
make promote
make import ENV=account
make import
make migrate-state # only needed if this env already has old mixed state
make plan
make applyA known Databricks provider bug can reorder tag policy values after creation, causing a Terraform state mismatch. The tag policies themselves are usually created correctly; the failure is in provider/state reconciliation.
make apply reduces this significantly by:
- running
make sync-tagsthrough the Databricks SDK against the shared account layer before applying it - keeping
ignore_changes = [values]ondatabricks_tag_policy
That said, you may still occasionally see this error during the account apply, especially when creating or adopting policies for the first time. In that case:
- Re-run
make apply - If it still fails, import the affected policies into the account state and retry
Manual recovery:
cd envs/account
python3 -c "import hcl2; d=hcl2.load(open('abac.auto.tfvars')); [print(tp['key']) for tp in d.get('tag_policies',[])]" | \
while read key; do
../../scripts/terraform_layer.sh account account state-rm "module.account.databricks_tag_policy.policies[\"$key\"]" 2>/dev/null || true
../../scripts/terraform_layer.sh account account import "module.account.databricks_tag_policy.policies[\"$key\"]" "$key" || true
done
make applyResources such as groups or tag policies already exist in Databricks. Import them so Terraform can manage them:
make import ENV=devIf a previous partial destroy removed the Terraform-managed SP grant before masking functions were dropped, rerun with the current code first. The current implementation keeps the SP grant ordered correctly during destroy and can temporarily re-establish the required catalog and schema access during masking-function teardown.
If you are still recovering an older partial state:
- Re-run
make destroy ENV=<workspace> - If needed,
make apply ENV=<workspace>first, then destroy again - Only destroy
ENV=accountafter the workspace environments that depend on it are gone
The Foundation Model API sometimes returns truncated output, especially with complex schemas (many tables/columns) or long overlay prompts.
Solutions:
- Re-run
make generate— LLM output is non-deterministic, retries often succeed - Reduce prompt complexity: use fewer tables (
SPACE="Single Space") or fewer overlays - Try
make generate --dry-runto inspect the prompt without calling the LLM - If using country + industry overlays together, try generating with just one overlay first
- Keep each Genie Space to 4-8 tables for reliable generation
The LLM may misclassify columns (e.g., applying mask_pan_india to credit card PAN instead of India tax PAN).
Solutions:
- Use unambiguous column names:
pan_numberinstead ofpan,card_numberinstead ofpan - Add clear column COMMENTs in your DDL — the LLM reads these during generation
- Edit
envs/<env>/generated/abac.auto.tfvarsto fix misclassifications, then runmake validate-generated - The autofix system catches some mismatches (function category vs. column category), but not all
Databricks enforces a platform limit of 10 FGAC policies per catalog. If your schema has many sensitive columns, the LLM may generate more than 10 policies.
Symptoms: make validate-generated errors with "exceeds Databricks platform limit of 10", or make apply fails with a provider error.
Solutions:
- Consolidate policies: use one masking function for multiple columns with the same sensitivity level
- Use tag-based conditions to group columns (e.g., all
pii_level=maskedcolumns share one policy) - Split tables across multiple catalogs if governance requirements differ
- The autofix system automatically drops excess policies — review which survived in the generated config
If make apply fails partway through, Terraform state may be inconsistent with actual cloud resources.
Solutions:
- Run
make planto see what Terraform thinks needs to change - If resources exist but aren't in state:
make import ENV=<env> - If state references deleted resources: run
terraform state rm <resource_address>in the appropriate layer directory - As a last resort:
make destroy ENV=<env>and re-apply from scratch - Never edit
.tfstatefiles directly
The governance warehouse may not exist, be stopped, or fail to create.
Solutions:
- If using an existing warehouse: verify
sql_warehouse_idinenv.auto.tfvarsis correct - If auto-creating: ensure the SP has
CAN_MANAGEentitlement on SQL warehouses - Check warehouse status in the Databricks UI — it may be stopped or in error state
- For serverless warehouses: ensure serverless compute is enabled for your workspace
Permission errors when fetching table DDL or applying governance.
Solutions:
- Verify the SP has
MANAGEpermission on the catalog (required for tag assignments) - For account-level operations (groups, tag policies): the SP needs Account Admin role
- Check
auth.auto.tfvarscredentials match the correct workspace - Run
make setup ENV=<env>to verify the SP can connect
The Genie Space REST API may return 429 (rate limit) or timeout errors during import or config push.
Solutions:
- Re-run
make generate— transient API errors resolve on retry - If consistent 403 errors: the SP may not have permission to manage Genie Spaces
- For large spaces with many tables: the API may timeout — reduce the number of tables per space
- Check workspace network connectivity if behind a firewall/VPN
FGAC policies reference masking functions that don't exist in the catalog.
Solutions:
- Run
make applyagain — the masking function deployment may have failed silently on the first attempt - Verify the SQL file:
cat envs/<env>/generated/masking_functions.sql— check for syntax errors - Check the catalog and schema exist: functions are created in the same catalog/schema as your tables
- Verify the SP has
CREATE FUNCTIONprivilege on the schema
Tag assignments were applied but don't appear in the Databricks UI.
Solutions:
- Wait 30-60 seconds — tag propagation is eventually consistent
- Run
make sync-tagsto force synchronization via the SDK - Check
make planto see if Terraform thinks the tags need to be created - Verify the tag policy exists in the account layer:
make plan ENV=account