terraform: Module copy copies outputs and dependencies
This commit is contained in:
parent
30cf550fc5
commit
af3c3e4c60
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue