Filter nil Deposed values during State init

The Deposed slice wasn't being normalized and nil values could be read
in from a state file. Filter out the nils during init. There is
still a bug in copystructure, but that will be addressed separately.
This commit is contained in:
James Bardin 2016-10-13 12:10:57 -04:00
parent fe4799bd68
commit 816c04309c
2 changed files with 13 additions and 2 deletions

View File

@ -1403,9 +1403,18 @@ func (s *ResourceState) init() {
s.Deposed = make([]*InstanceState, 0)
}
for _, dep := range s.Deposed {
dep.init()
// clean out any possible nil values read in from the state file
end := len(s.Deposed) - 1
for i := 0; i <= end; i++ {
if s.Deposed[i] == nil {
s.Deposed[i], s.Deposed[end] = s.Deposed[end], s.Deposed[i]
end--
i--
} else {
s.Deposed[i].init()
}
}
s.Deposed = s.Deposed[:end+1]
}
func (s *ResourceState) deepcopy() *ResourceState {

View File

@ -283,6 +283,8 @@ func TestStateDeepCopy(t *testing.T) {
},
},
// Deposed
// The nil values shouldn't be there if the State was properly init'ed,
// but the Copy should still work anyway.
{
&State{
Version: 6,