terraform: make DeepCopy public
This commit is contained in:
parent
ed6128aa6e
commit
f3af221866
|
@ -224,7 +224,7 @@ func (c *Context) Apply() (*State, error) {
|
||||||
defer c.releaseRun(v)
|
defer c.releaseRun(v)
|
||||||
|
|
||||||
// Copy our own state
|
// Copy our own state
|
||||||
c.state = c.state.deepcopy()
|
c.state = c.state.DeepCopy()
|
||||||
|
|
||||||
// Do the walk
|
// Do the walk
|
||||||
_, err := c.walk(walkApply)
|
_, err := c.walk(walkApply)
|
||||||
|
@ -264,7 +264,7 @@ func (c *Context) Plan(opts *PlanOpts) (*Plan, error) {
|
||||||
c.state = &State{}
|
c.state = &State{}
|
||||||
c.state.init()
|
c.state.init()
|
||||||
} else {
|
} else {
|
||||||
c.state = old.deepcopy()
|
c.state = old.DeepCopy()
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
c.state = old
|
c.state = old
|
||||||
|
@ -299,7 +299,7 @@ func (c *Context) Refresh() (*State, error) {
|
||||||
defer c.releaseRun(v)
|
defer c.releaseRun(v)
|
||||||
|
|
||||||
// Copy our own state
|
// Copy our own state
|
||||||
c.state = c.state.deepcopy()
|
c.state = c.state.DeepCopy()
|
||||||
|
|
||||||
// Do the walk
|
// Do the walk
|
||||||
if _, err := c.walk(walkRefresh); err != nil {
|
if _, err := c.walk(walkRefresh); err != nil {
|
||||||
|
|
|
@ -188,6 +188,26 @@ func (s *State) Equal(other *State) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeepCopy performs a deep copy of the state structure and returns
|
||||||
|
// a new structure.
|
||||||
|
func (s *State) DeepCopy() *State {
|
||||||
|
if s == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
n := &State{
|
||||||
|
Version: s.Version,
|
||||||
|
Serial: s.Serial,
|
||||||
|
Modules: make([]*ModuleState, 0, len(s.Modules)),
|
||||||
|
}
|
||||||
|
for _, mod := range s.Modules {
|
||||||
|
n.Modules = append(n.Modules, mod.deepcopy())
|
||||||
|
}
|
||||||
|
if s.Remote != nil {
|
||||||
|
n.Remote = s.Remote.deepcopy()
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
// IncrementSerialMaybe increments the serial number of this state
|
// IncrementSerialMaybe increments the serial number of this state
|
||||||
// if it different from the other state.
|
// if it different from the other state.
|
||||||
func (s *State) IncrementSerialMaybe(other *State) {
|
func (s *State) IncrementSerialMaybe(other *State) {
|
||||||
|
@ -209,24 +229,6 @@ func (s *State) init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) deepcopy() *State {
|
|
||||||
if s == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
n := &State{
|
|
||||||
Version: s.Version,
|
|
||||||
Serial: s.Serial,
|
|
||||||
Modules: make([]*ModuleState, 0, len(s.Modules)),
|
|
||||||
}
|
|
||||||
for _, mod := range s.Modules {
|
|
||||||
n.Modules = append(n.Modules, mod.deepcopy())
|
|
||||||
}
|
|
||||||
if s.Remote != nil {
|
|
||||||
n.Remote = s.Remote.deepcopy()
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// prune is used to remove any resources that are no longer required
|
// prune is used to remove any resources that are no longer required
|
||||||
func (s *State) prune() {
|
func (s *State) prune() {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
Loading…
Reference in New Issue