Skip to content

Commit 7602a35

Browse files
authored
direct: initialize "remote" in "changes" properly (#4451)
## Changes When populating "remote" in "changes", look up value from remote state, do not assume it's equal to "new" from config. ## Why This is correct value for this field. The downside is that we can now have changes for parent and child fields separately in "changes" but it's not clear if it has any downides. ## Tests Existing tests.
1 parent 895730d commit 7602a35

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

acceptance/bundle/config-remote-sync/config_edits/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Deployment complete!
2222
Detected changes in 1 resource(s):
2323

2424
Resource: resources.jobs.my_job
25+
email_notifications.on_failure: replace
2526
email_notifications.on_failure[0]: replace
2627
max_concurrent_runs: replace
2728
tags['env']: remove

bundle/direct/bundle_plan.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks
261261
}
262262
}
263263

264-
entry.Changes, err = prepareChanges(ctx, adapter, localDiff, remoteDiff, savedState, remoteState != nil)
264+
entry.Changes, err = prepareChanges(ctx, adapter, localDiff, remoteDiff, savedState, remoteStateComparable)
265265
if err != nil {
266266
logdiag.LogError(ctx, fmt.Errorf("%s: %w", errorPrefix, err))
267267
return false
@@ -316,17 +316,17 @@ func getMaxAction(m map[string]*deployplan.ChangeDesc) deployplan.ActionType {
316316
return result
317317
}
318318

319-
func prepareChanges(ctx context.Context, adapter *dresources.Adapter, localDiff, remoteDiff []structdiff.Change, oldState any, hasRemote bool) (deployplan.Changes, error) {
319+
func prepareChanges(ctx context.Context, adapter *dresources.Adapter, localDiff, remoteDiff []structdiff.Change, oldState, remoteState any) (deployplan.Changes, error) {
320320
m := make(deployplan.Changes)
321321

322322
for _, ch := range localDiff {
323323
e := deployplan.ChangeDesc{
324324
Old: ch.Old,
325325
New: ch.New,
326326
}
327-
if hasRemote {
328-
// by default, assume e.Remote is the same as config; if not the case it'll be ovewritten below
329-
e.Remote = ch.New
327+
if remoteState != nil {
328+
// We cannot assume e.Remote is the same as config: if the whole struct is missing, there might be diff entry for parent
329+
e.Remote, _ = structaccess.Get(remoteState, ch.Path)
330330
}
331331
m[ch.Path.String()] = &e
332332
}

0 commit comments

Comments
 (0)