terraform: state mv "foo" to "foo.0" with single count
This commit is contained in:
parent
88649ed010
commit
8afbb0ee0e
|
@ -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)
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue