Skip to content

Commit 6b0282f

Browse files
authored
direct: Fix spurious recreate of schemas and volumes with mixed-case names (#5531)
The direct engine saves local config to state, so when Unity Catalog lowercases a schema/volume identifier, the next deploy sees the original mixed-case value drift against the normalized remote value and recreates/renames the resource — on every second deploy with no config changes. This PR fixes that. The fix is expressed declaratively via a new `resources.yml` key, `normalize_case`. The same mechanism also absorbs the existing trailing-slash `storage_location` suppression (#5145) as a second key, `normalize_slash` — a refactor of behavior that already lived in per-resource `OverrideChangeDesc` methods, not a new behavior.
1 parent dd2220a commit 6b0282f

22 files changed

Lines changed: 258 additions & 35 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Mark vector search index index_subtype as backend_default to prevent drift after deployment ([#5454](https://github.com/databricks/cli/pull/5454)).
1919
* `bundle deployment migrate`: handle resources added to or removed from `databricks.yml` since the last Terraform deploy ([#5463](https://github.com/databricks/cli/pull/5463)).
2020
* Add the `genie_spaces` bundle resource for managing Databricks Genie spaces as code, plus `bundle generate genie-space` to import an existing space. Direct deployment engine only ([#5282](https://github.com/databricks/cli/pull/5282)).
21+
* Fix spurious recreate of schemas and volumes whose names use mixed case ([#5531](https://github.com/databricks/cli/pull/5531)).
2122

2223
### Dependency updates
2324

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
# Reproduce: UC API normalizes identifier names to lowercase, causing
5+
# false drift on the second deploy when the config uses mixed-case names.
6+
# Volumes are covered by acceptance/bundle/resources/volumes/uppercase-name
7+
# instead: the Terraform provider rejects an uppercase volume schema_name
8+
# ("inconsistent final plan"), and the migrate invariant always deploys via
9+
# Terraform first, so an uppercase volume cannot live in this shared config.
10+
resources:
11+
schemas:
12+
foo:
13+
catalog_name: main
14+
name: MySCHEMA-$UNIQUE_NAME
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
# Reproduce: the UC API lowercases identifier names, causing false drift on the
5+
# second deploy when the config uses mixed-case names. This covers a volume's
6+
# catalog_name, schema_name and name on the direct engine.
7+
#
8+
# Excluded from the migrate invariant: that test deploys via Terraform first,
9+
# and the TF provider rejects an uppercase volume schema_name ("inconsistent
10+
# final plan").
11+
resources:
12+
schemas:
13+
foo:
14+
catalog_name: main
15+
name: MySCHEMA-$UNIQUE_NAME
16+
17+
volumes:
18+
bar:
19+
catalog_name: main
20+
schema_name: ${resources.schemas.foo.name}
21+
name: MyVOL-$UNIQUE_NAME
22+
volume_type: MANAGED

acceptance/bundle/invariant/continue_293/out.test.toml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/invariant/migrate/out.test.toml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/invariant/migrate/test.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ EnvMatrixExclude.no_sql_warehouse = ["INPUT_CONFIG=sql_warehouse.yml.tmpl"]
2626
# The 1000-task scale case is covered by no_drift. Running it here adds ~1.5 min
2727
# per variant (deploy + migrate + plan at 1000 tasks) without incremental coverage.
2828
EnvMatrixExclude.no_pydabs_1000_tasks = ["INPUT_CONFIG=job_pydabs_1000_tasks.yml.tmpl"]
29+
30+
# migrate deploys via Terraform first, and the TF provider rejects an uppercase
31+
# volume schema_name ("inconsistent final plan"). Covered by no_drift on direct.
32+
EnvMatrixExclude.no_volume_uppercase = ["INPUT_CONFIG=volume_uppercase_name.yml.tmpl"]

acceptance/bundle/invariant/no_drift/out.test.toml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/invariant/test.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ EnvMatrix.INPUT_CONFIG = [
5252
"registered_model.yml.tmpl",
5353
"schema.yml.tmpl",
5454
"schema_grant_ref.yml.tmpl",
55+
"schema_uppercase_name.yml.tmpl",
5556
"schema_with_grants.yml.tmpl",
5657
"secret_scope.yml.tmpl",
5758
"secret_scope_default_backend_type.yml.tmpl",
@@ -62,6 +63,7 @@ EnvMatrix.INPUT_CONFIG = [
6263
"vector_search_index.yml.tmpl",
6364
"volume.yml.tmpl",
6465
"volume_external.yml.tmpl",
66+
"volume_uppercase_name.yml.tmpl",
6567
]
6668

6769
[EnvMatrixExclude]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bundle:
2+
name: test-bundle
3+
4+
resources:
5+
schemas:
6+
schema1:
7+
catalog_name: main
8+
name: MySCHEMA
9+
10+
volumes:
11+
vol1:
12+
catalog_name: main
13+
schema_name: MySCHEMA
14+
name: MyVOLUME
15+
volume_type: MANAGED
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
2+
Deploying resources...
3+
Updating deployment state...
4+
Deployment complete!
5+
{
6+
"method": "POST",
7+
"path": "/api/2.1/unity-catalog/schemas",
8+
"body": {
9+
"catalog_name": "main",
10+
"name": "MySCHEMA"
11+
}
12+
}
13+
{
14+
"method": "POST",
15+
"path": "/api/2.1/unity-catalog/volumes",
16+
"body": {
17+
"catalog_name": "main",
18+
"name": "MyVOLUME",
19+
"schema_name": "MySCHEMA",
20+
"volume_type": "MANAGED"
21+
}
22+
}
23+
=== Bundle summary shows lowercase IDs after UC normalizes names
24+
{
25+
"schema_id": "main.myschema",
26+
"volume_id": "main.myschema.myvolume"
27+
}
28+
=== Plan on no-op redeploy: mixed-case names are skipped, not recreated
29+
[
30+
{
31+
"resource": "resources.schemas.schema1",
32+
"changes": {
33+
"name": {
34+
"action": "skip",
35+
"reason": "uc_case"
36+
}
37+
}
38+
},
39+
{
40+
"resource": "resources.volumes.vol1",
41+
"changes": {
42+
"name": {
43+
"action": "skip",
44+
"reason": "uc_case"
45+
},
46+
"schema_name": {
47+
"action": "skip",
48+
"reason": "uc_case"
49+
},
50+
"storage_location": {
51+
"action": "skip",
52+
"reason": "backend_default"
53+
}
54+
}
55+
}
56+
]
57+
=== Redeploy without changes - should be a no-op
58+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
59+
Deploying resources...
60+
Updating deployment state...
61+
Deployment complete!

0 commit comments

Comments
 (0)