mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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:
parent
fe4799bd68
commit
816c04309c
@ -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 {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user