terraform: StateAdd edge case test for multi-count to single index

This commit is contained in:
Mitchell Hashimoto 2016-08-19 11:51:31 -04:00
parent a22f7e8257
commit 88649ed010
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 32 additions and 0 deletions

View File

@ -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)
}
// 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
for i, rs := range list {
addrCopy := addr.Copy()

View File

@ -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)": {
true,
"aws_instance.bar",