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
|
||||
func (s *State) prune() {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
for _, mod := range s.Modules {
|
||||
mod.prune()
|
||||
}
|
||||
|
@ -392,12 +395,14 @@ func (i *InstanceState) deepcopy() *InstanceState {
|
|||
}
|
||||
n := &InstanceState{
|
||||
ID: i.ID,
|
||||
Attributes: make(map[string]string, len(i.Attributes)),
|
||||
Ephemeral: *i.Ephemeral.deepcopy(),
|
||||
}
|
||||
if i.Attributes != nil {
|
||||
n.Attributes = make(map[string]string, len(i.Attributes))
|
||||
for k, v := range i.Attributes {
|
||||
n.Attributes[k] = v
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
|
@ -489,12 +494,13 @@ func (e *EphemeralState) deepcopy() *EphemeralState {
|
|||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
n := &EphemeralState{
|
||||
ConnInfo: make(map[string]string, len(e.ConnInfo)),
|
||||
}
|
||||
n := &EphemeralState{}
|
||||
if e.ConnInfo != nil {
|
||||
n.ConnInfo = make(map[string]string, len(e.ConnInfo))
|
||||
for k, v := range e.ConnInfo {
|
||||
n.ConnInfo[k] = v
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue