-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathdiff.go
More file actions
47 lines (37 loc) · 1.43 KB
/
diff.go
File metadata and controls
47 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package configsync
import (
"context"
"fmt"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/deployplan"
"github.com/databricks/cli/bundle/direct"
"github.com/databricks/cli/libs/log"
)
// DetectChanges compares current remote state with the last deployed state
// and returns a map of resource changes.
func DetectChanges(ctx context.Context, b *bundle.Bundle) (map[string]deployplan.Changes, error) {
changes := make(map[string]deployplan.Changes)
deployBundle := &direct.DeploymentBundle{}
// TODO: for Terraform engine we should read the state file, converted to direct state format, it should be created during deployment
_, statePath := b.StateFilenameDirect(ctx)
plan, err := deployBundle.CalculatePlan(ctx, b.WorkspaceClient(), &b.Config, statePath)
if err != nil {
return nil, fmt.Errorf("failed to calculate plan: %w", err)
}
for resourceKey, entry := range plan.Plan {
resourceChanges := make(deployplan.Changes)
if entry.Changes != nil {
for path, changeDesc := range entry.Changes {
// TODO: distinguish action Skip between actual server-side defaults and remote-side changes
if changeDesc.Remote != nil && changeDesc.Action != deployplan.Skip {
resourceChanges[path] = changeDesc
}
}
}
if len(resourceChanges) != 0 {
changes[resourceKey] = resourceChanges
}
log.Debugf(ctx, "Resource %s has %d changes", resourceKey, len(resourceChanges))
}
return changes, nil
}