Skip to content

Commit 75c185d

Browse files
authored
Fix ignore_{remote,local}_changes setting in resource.yml (#4388)
## Changes - Fix ignore_remote_changes to ignoring only remote changes (it was ignoring all on a given path). - Respect ignore_local_changes setting. Currently, few resources use it (experiments, database_catalogs, synced_database_tables since #4364). Follow up to #4304 ## Tests Existing. I have follow up PRs that make more use of ignore_remote_changes which make this bug apparent.
1 parent e75d01e commit 75c185d

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bundles
1010

1111
* Add missing values to SchemaGrantPrivilege enum ([#4380](https://github.com/databricks/cli/pull/4380))
12+
* engine/direct: Fix updates to fields being ignored for database_catalogs, synced_database_tables (([#4388](https://github.com/databricks/cli/pull/4388)))
1213

1314
### Dependency updates
1415

bundle/direct/bundle_plan.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ func addPerFieldActions(ctx context.Context, adapter *dresources.Adapter, change
383383
// Empty struct in config should not cause drift when remote has values
384384
ch.Action = deployplan.Skip
385385
ch.Reason = deployplan.ReasonEmptyStruct
386-
} else if action := shouldIgnore(cfg, path); action != deployplan.Undefined {
387-
ch.Action = action
386+
} else if shouldSkip(cfg, path, ch) {
387+
ch.Action = deployplan.Skip
388388
ch.Reason = deployplan.ReasonBuiltinRule
389389
} else if ch.New == nil && ch.Old == nil && ch.Remote != nil && path.IsDotString() {
390390
// The field was not set by us, but comes from the remote state.
@@ -419,31 +419,37 @@ func addPerFieldActions(ctx context.Context, adapter *dresources.Adapter, change
419419
return nil
420420
}
421421

422-
func shouldIgnore(cfg *dresources.ResourceLifecycleConfig, path *structpath.PathNode) deployplan.ActionType {
423-
if cfg == nil {
424-
return deployplan.Undefined
425-
}
426-
for _, p := range cfg.IgnoreRemoteChanges {
422+
func matchesAnyPrefix(path *structpath.PathNode, prefixes []*structpath.PathNode) bool {
423+
for _, p := range prefixes {
427424
if path.HasPrefix(p) {
428-
return deployplan.Skip
425+
return true
429426
}
430427
}
431-
return deployplan.Undefined
428+
return false
429+
}
430+
431+
func shouldSkip(cfg *dresources.ResourceLifecycleConfig, path *structpath.PathNode, ch *deployplan.ChangeDesc) bool {
432+
if cfg == nil {
433+
return false
434+
}
435+
if matchesAnyPrefix(path, cfg.IgnoreLocalChanges) && !structdiff.IsEqual(ch.Old, ch.New) {
436+
return true
437+
}
438+
if matchesAnyPrefix(path, cfg.IgnoreRemoteChanges) && structdiff.IsEqual(ch.Old, ch.New) {
439+
return true
440+
}
441+
return false
432442
}
433443

434444
func shouldUpdateOrRecreate(cfg *dresources.ResourceLifecycleConfig, path *structpath.PathNode) deployplan.ActionType {
435445
if cfg == nil {
436446
return deployplan.Undefined
437447
}
438-
for _, p := range cfg.RecreateOnChanges {
439-
if path.HasPrefix(p) {
440-
return deployplan.Recreate
441-
}
448+
if matchesAnyPrefix(path, cfg.RecreateOnChanges) {
449+
return deployplan.Recreate
442450
}
443-
for _, p := range cfg.UpdateIDOnChanges {
444-
if path.HasPrefix(p) {
445-
return deployplan.UpdateWithID
446-
}
451+
if matchesAnyPrefix(path, cfg.UpdateIDOnChanges) {
452+
return deployplan.UpdateWithID
447453
}
448454
return deployplan.Undefined
449455
}

bundle/direct/dresources/resources.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ resources:
4040
ignore_remote_changes:
4141
# Tags updates are not supported by TF. This mirrors that behaviour.
4242
- tags
43+
ignore_local_changes:
44+
- tags
4345

4446
# TF implementation: https://github.com/databricks/terraform-provider-databricks/blob/6c106e8e7052bb2726148d66309fd460ed444236/mlflow/resource_mlflow_experiment.go#L22
4547
model_serving_endpoints:

0 commit comments

Comments
 (0)