Specify fields on engine diff
This commit is contained in:
parent
52d01bb915
commit
b16ed8a16d
|
@ -1132,11 +1132,7 @@ func diffResource(urn resource.URN, id resource.ID, oldInputs, oldOutputs,
|
|||
return diff, err
|
||||
}
|
||||
if diff.Changes == plugin.DiffUnknown {
|
||||
if oldInputs.DeepEquals(newInputs) {
|
||||
diff.Changes = plugin.DiffNone
|
||||
} else {
|
||||
diff.Changes = plugin.DiffSome
|
||||
}
|
||||
diff = plugin.NewDiffResultFromObjectDiff(oldInputs.Diff(newInputs))
|
||||
}
|
||||
return diff, nil
|
||||
}
|
||||
|
|
|
@ -217,6 +217,27 @@ type DiffResult struct {
|
|||
DeleteBeforeReplace bool // if true, this resource must be deleted before recreating it.
|
||||
}
|
||||
|
||||
// Transforms a `ObjectDiff` into an equivalent `DiffResult`. Because ObjectDiff has no way of
|
||||
// determining what should be changed vs replaced, all operations are added to the ChangedKeys set.
|
||||
func NewDiffResultFromObjectDiff(obj *resource.ObjectDiff) DiffResult {
|
||||
result := DiffResult{}
|
||||
if !obj.AnyChanges() {
|
||||
result.Changes = DiffNone
|
||||
return result
|
||||
}
|
||||
|
||||
result.Changes = DiffSome
|
||||
for _, k := range obj.Keys() {
|
||||
if obj.Changed(k) {
|
||||
result.ChangedKeys = append(result.ChangedKeys, k)
|
||||
} else {
|
||||
result.StableKeys = append(result.StableKeys, k)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Replace returns true if this diff represents a replacement.
|
||||
func (r DiffResult) Replace() bool {
|
||||
for _, v := range r.DetailedDiff {
|
||||
|
|
|
@ -55,6 +55,12 @@ func (diff *ObjectDiff) Same(k PropertyKey) bool {
|
|||
return !diff.Changed(k)
|
||||
}
|
||||
|
||||
// Returns true if there are no changes (adds, deletes, updates) in the diff. Also returns true if
|
||||
// diff is nil. Otherwise returns false.
|
||||
func (diff *ObjectDiff) AnyChanges() bool {
|
||||
return diff != nil && len(diff.Adds)+len(diff.Deletes)+len(diff.Updates) > 0
|
||||
}
|
||||
|
||||
// Keys returns a stable snapshot of all keys known to this object, across adds, deletes, sames, and updates.
|
||||
func (diff *ObjectDiff) Keys() []PropertyKey {
|
||||
var ks []PropertyKey
|
||||
|
|
Loading…
Reference in a new issue