terraform: copy deps and provider for resource state

This commit is contained in:
Mitchell Hashimoto 2016-04-11 18:29:51 -07:00
parent cb060f9063
commit e65a726936
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 35 additions and 4 deletions

View File

@ -95,7 +95,7 @@ func stateAddFunc_Module_Module(s *State, addr *ResourceAddress, raw interface{}
}
func stateAddFunc_Resource_Resource(s *State, addr *ResourceAddress, raw interface{}) error {
src := raw.(*ResourceState)
src := raw.(*ResourceState).deepcopy()
// Initialize the resource
resourceRaw, exists := stateAddInitAddr(s, addr)
@ -104,9 +104,8 @@ func stateAddFunc_Resource_Resource(s *State, addr *ResourceAddress, raw interfa
}
resource := resourceRaw.(*ResourceState)
resource.Type = src.Type
// TODO: Dependencies
// TODO: Provider?
resource.Dependencies = src.Dependencies
resource.Provider = src.Provider
// Move the primary
if src.Primary != nil {

View File

@ -163,6 +163,38 @@ func TestStateAdd(t *testing.T) {
},
},
"ResourceState w/ deps, provider => Resource Addr (new)": {
false,
"aws_instance.foo",
&ResourceState{
Type: "test_instance",
Provider: "foo",
Dependencies: []string{"bar"},
Primary: &InstanceState{
ID: "foo",
},
},
&State{},
&State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root"},
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "test_instance",
Provider: "foo",
Dependencies: []string{"bar"},
Primary: &InstanceState{
ID: "foo",
},
},
},
},
},
},
},
"ResourceState => Resource Addr (existing)": {
true,
"aws_instance.foo",