terraform: state mv "foo" to "foo.0" with single count

This commit is contained in:
Mitchell Hashimoto 2016-08-19 11:54:53 -04:00
parent 88649ed010
commit 8afbb0ee0e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 61 additions and 1 deletions

View File

@ -162,7 +162,7 @@ func stateAddFunc_Resource_Resource(s *State, fromAddr, addr *ResourceAddress, r
// If there is an index, this is an error since we can't assign // If there is an index, this is an error since we can't assign
// a set of resources to a single index // a set of resources to a single index
if addr.Index >= 0 { if addr.Index >= 0 && len(list) > 1 {
return fmt.Errorf( return fmt.Errorf(
"multiple resources can't be moved to a single index: "+ "multiple resources can't be moved to a single index: "+
"%s => %s", fromAddr, addr) "%s => %s", fromAddr, addr)

View File

@ -440,6 +440,66 @@ func TestStateAdd(t *testing.T) {
nil, nil,
}, },
"ResourceState with single count unspecified => Resource Addr (new with count)": {
false,
"aws_instance.bar",
"aws_instance.foo[0]",
[]*ResourceState{
&ResourceState{
Type: "test_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
&State{},
&State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root"},
Resources: map[string]*ResourceState{
"aws_instance.foo.0": &ResourceState{
Type: "test_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
},
},
},
"ResourceState => Resource Addr (new with count)": {
false,
"aws_instance.bar",
"aws_instance.foo[0]",
&ResourceState{
Type: "test_instance",
Primary: &InstanceState{
ID: "foo",
},
},
&State{},
&State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root"},
Resources: map[string]*ResourceState{
"aws_instance.foo.0": &ResourceState{
Type: "test_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
},
},
},
"ResourceState => Resource Addr (existing)": { "ResourceState => Resource Addr (existing)": {
true, true,
"aws_instance.bar", "aws_instance.bar",