add ChangesSync.FullDestroy

In order to handle various edge cases during a full destroy, add
FullDestroy to the synchronized changes so we can attempt to deduce if
the plan was created from `terraform destroy`.

It's possible that the plan was created by removing all resourced from
the configuration, but in that case the end result is the same. Any of
the edge cases with provider or destroy provisioner configurations would
not apply, since there would not be any configuration references to
resolve.
This commit is contained in:
James Bardin 2020-10-01 17:08:25 -04:00
parent a7e43dfd46
commit fa8f8df7b6
1 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,24 @@ type ChangesSync struct {
changes *Changes
}
// FullDestroy returns true if the set of changes indicates we are doing a
// destroy of all resources.
func (cs *ChangesSync) FullDestroy() bool {
if cs == nil {
panic("FullDestroy on nil ChangesSync")
}
cs.lock.Lock()
defer cs.lock.Unlock()
for _, c := range cs.changes.Resources {
if c.Action != Delete {
return false
}
}
return true
}
// AppendResourceInstanceChange records the given resource instance change in
// the set of planned resource changes.
//