mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 12:17:39 -06:00
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)
|
||||
|
||||
// Copy our own state
|
||||
c.state = c.state.deepcopy()
|
||||
c.state = c.state.DeepCopy()
|
||||
|
||||
// Do the walk
|
||||
_, err := c.walk(walkApply)
|
||||
@ -264,7 +264,7 @@ func (c *Context) Plan(opts *PlanOpts) (*Plan, error) {
|
||||
c.state = &State{}
|
||||
c.state.init()
|
||||
} else {
|
||||
c.state = old.deepcopy()
|
||||
c.state = old.DeepCopy()
|
||||
}
|
||||
defer func() {
|
||||
c.state = old
|
||||
@ -299,7 +299,7 @@ func (c *Context) Refresh() (*State, error) {
|
||||
defer c.releaseRun(v)
|
||||
|
||||
// Copy our own state
|
||||
c.state = c.state.deepcopy()
|
||||
c.state = c.state.DeepCopy()
|
||||
|
||||
// Do the walk
|
||||
if _, err := c.walk(walkRefresh); err != nil {
|
||||
|
@ -188,6 +188,26 @@ func (s *State) Equal(other *State) bool {
|
||||
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
|
||||
// if it different from the 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
|
||||
func (s *State) prune() {
|
||||
if s == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user