terraform: deepcopy should not alloc when nil
This commit is contained in:
parent
8e421caba1
commit
1d96373a54
|
@ -94,6 +94,9 @@ func (s *State) deepcopy() *State {
|
||||||
|
|
||||||
// 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 {
|
||||||
|
return
|
||||||
|
}
|
||||||
for _, mod := range s.Modules {
|
for _, mod := range s.Modules {
|
||||||
mod.prune()
|
mod.prune()
|
||||||
}
|
}
|
||||||
|
@ -391,12 +394,14 @@ func (i *InstanceState) deepcopy() *InstanceState {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
n := &InstanceState{
|
n := &InstanceState{
|
||||||
ID: i.ID,
|
ID: i.ID,
|
||||||
Attributes: make(map[string]string, len(i.Attributes)),
|
Ephemeral: *i.Ephemeral.deepcopy(),
|
||||||
Ephemeral: *i.Ephemeral.deepcopy(),
|
|
||||||
}
|
}
|
||||||
for k, v := range i.Attributes {
|
if i.Attributes != nil {
|
||||||
n.Attributes[k] = v
|
n.Attributes = make(map[string]string, len(i.Attributes))
|
||||||
|
for k, v := range i.Attributes {
|
||||||
|
n.Attributes[k] = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
@ -489,11 +494,12 @@ func (e *EphemeralState) deepcopy() *EphemeralState {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
n := &EphemeralState{
|
n := &EphemeralState{}
|
||||||
ConnInfo: make(map[string]string, len(e.ConnInfo)),
|
if e.ConnInfo != nil {
|
||||||
}
|
n.ConnInfo = make(map[string]string, len(e.ConnInfo))
|
||||||
for k, v := range e.ConnInfo {
|
for k, v := range e.ConnInfo {
|
||||||
n.ConnInfo[k] = v
|
n.ConnInfo[k] = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue