terraform: StateAdd edge case test for multi-count to single index
This commit is contained in:
parent
a22f7e8257
commit
88649ed010
|
@ -160,6 +160,14 @@ func stateAddFunc_Resource_Resource(s *State, fromAddr, addr *ResourceAddress, r
|
||||||
return fmt.Errorf("resource move with no value to: %s", addr)
|
return fmt.Errorf("resource move with no value to: %s", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is an index, this is an error since we can't assign
|
||||||
|
// a set of resources to a single index
|
||||||
|
if addr.Index >= 0 {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"multiple resources can't be moved to a single index: "+
|
||||||
|
"%s => %s", fromAddr, addr)
|
||||||
|
}
|
||||||
|
|
||||||
// Add each with a specific index
|
// Add each with a specific index
|
||||||
for i, rs := range list {
|
for i, rs := range list {
|
||||||
addrCopy := addr.Copy()
|
addrCopy := addr.Copy()
|
||||||
|
|
|
@ -416,6 +416,30 @@ func TestStateAdd(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"ResourceState with count unspecified => Resource Addr (new with count)": {
|
||||||
|
true,
|
||||||
|
"aws_instance.bar",
|
||||||
|
"aws_instance.foo[0]",
|
||||||
|
[]*ResourceState{
|
||||||
|
&ResourceState{
|
||||||
|
Type: "test_instance",
|
||||||
|
Primary: &InstanceState{
|
||||||
|
ID: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
&ResourceState{
|
||||||
|
Type: "test_instance",
|
||||||
|
Primary: &InstanceState{
|
||||||
|
ID: "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
&State{},
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
|
||||||
"ResourceState => Resource Addr (existing)": {
|
"ResourceState => Resource Addr (existing)": {
|
||||||
true,
|
true,
|
||||||
"aws_instance.bar",
|
"aws_instance.bar",
|
||||||
|
|
Loading…
Reference in New Issue