Set proper Mode when moving a data source in state

ResourceAddr.Mode wasn't properly set when moving a module, so data
sources would lose the "data." prefix when their module was moved within
the State.
This commit is contained in:
James Bardin 2016-11-21 18:26:29 -05:00
parent c908f3ceae
commit 705527e6fe
2 changed files with 37 additions and 2 deletions

View File

@ -113,7 +113,7 @@ func stateAddFunc_Module_Module(s *State, fromAddr, addr *ResourceAddress, raw i
addrCopy.Type = resourceKey.Type
addrCopy.Name = resourceKey.Name
addrCopy.Index = resourceKey.Index
//addrCopy.Mode = resourceKey.Mode
addrCopy.Mode = resourceKey.Mode
// Perform an add
if err := s.Add(fromAddr.String(), addrCopy.String(), v); err != nil {
@ -333,7 +333,7 @@ func stateAddInitAddr(s *State, addr *ResourceAddress) (interface{}, bool) {
Name: addr.Name,
Type: addr.Type,
Index: addr.Index,
//Mode: addr.Mode,
Mode: addr.Mode,
}).String()
exists = true
resource, ok := mod.Resources[resourceKey]

View File

@ -627,6 +627,41 @@ func TestStateAdd(t *testing.T) {
},
},
},
{
"ModuleState => Module Addr (new with data source)",
false,
"",
"module.foo",
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"data.test_instance.foo": &ResourceState{
Type: "test_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
&State{},
&State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "foo"},
Resources: map[string]*ResourceState{
"data.test_instance.foo": &ResourceState{
Type: "test_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
},
},
},
}
for i, tc := range cases {