mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-24 16:10:46 -06:00
terraform: build a plan
This commit is contained in:
parent
f7a6cbf247
commit
686b563428
@ -157,6 +157,16 @@ type ResourceAttrDiff struct {
|
|||||||
RequiresNew bool // True if change requires new resource
|
RequiresNew bool // True if change requires new resource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty returns true if this diff encapsulates no changes.
|
||||||
|
// TODO(mitchellh): test
|
||||||
|
func (d *ResourceDiff) Empty() bool {
|
||||||
|
if d == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(d.Attributes) == 0
|
||||||
|
}
|
||||||
|
|
||||||
// RequiresNew returns true if the diff requires the creation of a new
|
// RequiresNew returns true if the diff requires the creation of a new
|
||||||
// resource (implying the destruction of the old).
|
// resource (implying the destruction of the old).
|
||||||
func (d *ResourceDiff) RequiresNew() bool {
|
func (d *ResourceDiff) RequiresNew() bool {
|
||||||
|
@ -172,6 +172,10 @@ func (t *Terraform) planWalkFn(
|
|||||||
// Initialize the result diff so we can write to it
|
// Initialize the result diff so we can write to it
|
||||||
result.init()
|
result.init()
|
||||||
|
|
||||||
|
// Write our configuration out
|
||||||
|
result.Config = t.config
|
||||||
|
result.Vars = t.variables
|
||||||
|
|
||||||
cb := func(r *Resource) (map[string]string, error) {
|
cb := func(r *Resource) (map[string]string, error) {
|
||||||
// Refresh the state so we're working with the latest resource info
|
// Refresh the state so we're working with the latest resource info
|
||||||
newState, err := r.Provider.Refresh(r.State)
|
newState, err := r.Provider.Refresh(r.State)
|
||||||
@ -185,19 +189,19 @@ func (t *Terraform) planWalkFn(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there were no diff items, return right away
|
|
||||||
if diff == nil || len(diff.Attributes) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the resulting diff
|
|
||||||
l.Lock()
|
l.Lock()
|
||||||
|
if !diff.Empty() {
|
||||||
result.Diff.Resources[r.Id] = diff
|
result.Diff.Resources[r.Id] = diff
|
||||||
|
}
|
||||||
|
result.State.Resources[r.Id] = newState
|
||||||
l.Unlock()
|
l.Unlock()
|
||||||
|
|
||||||
// Determine the new state and update variables
|
// Determine the new state and update variables
|
||||||
vars := make(map[string]string)
|
vars := make(map[string]string)
|
||||||
rs := r.State.MergeDiff(diff)
|
rs := newState
|
||||||
|
if !diff.Empty() {
|
||||||
|
rs = r.State.MergeDiff(diff)
|
||||||
|
}
|
||||||
for ak, av := range rs.Attributes {
|
for ak, av := range rs.Attributes {
|
||||||
vars[fmt.Sprintf("%s.%s", r.Id, ak)] = av
|
vars[fmt.Sprintf("%s.%s", r.Id, ak)] = av
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user