terraform: instance => module

This commit is contained in:
Mitchell Hashimoto 2016-04-12 09:55:17 -07:00
parent 4d268b6eca
commit 163f19fd00
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 36 additions and 0 deletions

View File

@ -159,6 +159,15 @@ func stateAddFunc_Instance_Instance(s *State, fromAddr, addr *ResourceAddress, r
return nil
}
func stateAddFunc_Instance_Module(
s *State, from, to *ResourceAddress, raw interface{}) error {
addr := *to
addr.Type = from.Type
addr.Name = from.Name
return s.Add(from.String(), addr.String(), raw)
}
func stateAddFunc_Instance_Resource(
s *State, from, to *ResourceAddress, raw interface{}) error {
addr := *to
@ -185,6 +194,7 @@ func init() {
},
stateAddInstance: {
stateAddInstance: stateAddFunc_Instance_Instance,
stateAddModule: stateAddFunc_Instance_Module,
stateAddResource: stateAddFunc_Instance_Resource,
},
}

View File

@ -317,6 +317,32 @@ func TestStateAdd(t *testing.T) {
},
},
},
"InstanceState => Module (new)": {
false,
"aws_instance.bar.primary",
"module.foo",
&InstanceState{
ID: "foo",
},
&State{},
&State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "foo"},
Resources: map[string]*ResourceState{
"aws_instance.bar": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "foo",
},
},
},
},
},
},
},
}
for k, tc := range cases {