terraform: instance => resource

This commit is contained in:
Mitchell Hashimoto 2016-04-12 09:51:43 -07:00
parent e497c26517
commit 4d268b6eca
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 37 additions and 1 deletions

View File

@ -159,6 +159,15 @@ func stateAddFunc_Instance_Instance(s *State, fromAddr, addr *ResourceAddress, r
return nil
}
func stateAddFunc_Instance_Resource(
s *State, from, to *ResourceAddress, raw interface{}) error {
addr := *to
addr.InstanceType = TypePrimary
addr.InstanceTypeSet = true
return s.Add(from.String(), addr.String(), raw)
}
// stateAddFunc is the type of function for adding an item to a state
type stateAddFunc func(s *State, from, to *ResourceAddress, item interface{}) error
@ -176,6 +185,7 @@ func init() {
},
stateAddInstance: {
stateAddInstance: stateAddFunc_Instance_Instance,
stateAddResource: stateAddFunc_Instance_Resource,
},
}
}

View File

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