diff --git a/terraform/state.go b/terraform/state.go index 012221634..d2c61ac39 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -673,11 +673,13 @@ func (m *ModuleState) deepcopy() *ModuleState { return nil } n := &ModuleState{ - Path: make([]string, len(m.Path)), - Outputs: make(map[string]interface{}, len(m.Outputs)), - Resources: make(map[string]*ResourceState, len(m.Resources)), + Path: make([]string, len(m.Path)), + Outputs: make(map[string]interface{}, len(m.Outputs)), + Resources: make(map[string]*ResourceState, len(m.Resources)), + Dependencies: make([]string, len(m.Dependencies)), } copy(n.Path, m.Path) + copy(n.Dependencies, m.Dependencies) for k, v := range m.Outputs { n.Outputs[k] = v } diff --git a/terraform/state_add.go b/terraform/state_add.go index 9a485c0f8..74fa62255 100644 --- a/terraform/state_add.go +++ b/terraform/state_add.go @@ -59,7 +59,7 @@ func (s *State) Add(addrRaw string, raw interface{}) error { } func stateAddFunc_Module_Module(s *State, addr *ResourceAddress, raw interface{}) error { - src := raw.(*ModuleState) + src := raw.(*ModuleState).deepcopy() // If the target module exists, it is an error path := append([]string{"root"}, addr.Path...) @@ -67,8 +67,10 @@ func stateAddFunc_Module_Module(s *State, addr *ResourceAddress, raw interface{} return fmt.Errorf("module target is not empty: %s", addr) } - // TODO: outputs - // TODO: dependencies + // Create it and copy our outputs and dependencies + mod := s.AddModule(path) + mod.Outputs = src.Outputs + mod.Dependencies = src.Dependencies // Go through the resources perform an add for each of those for k, v := range src.Resources { diff --git a/terraform/state_test.go b/terraform/state_test.go index d9a53b69f..fdfd7a90a 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -478,6 +478,61 @@ func TestStateAdd(t *testing.T) { }, }, + "ModuleState w/ outputs and deps => Module Addr (new)": { + false, + "module.foo", + &ModuleState{ + Path: rootModulePath, + Outputs: map[string]interface{}{ + "foo": "bar", + }, + Dependencies: []string{"foo"}, + Resources: map[string]*ResourceState{ + "test_instance.foo": &ResourceState{ + Type: "test_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + + "test_instance.bar": &ResourceState{ + Type: "test_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + }, + }, + + &State{}, + &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: []string{"root", "foo"}, + Outputs: map[string]interface{}{ + "foo": "bar", + }, + Dependencies: []string{"foo"}, + Resources: map[string]*ResourceState{ + "test_instance.foo": &ResourceState{ + Type: "test_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + + "test_instance.bar": &ResourceState{ + Type: "test_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + }, + }, + }, + }, + }, + "ModuleState => Module Addr (existing)": { true, "module.foo",