diff --git a/terraform/state_add.go b/terraform/state_add.go index c7d45e0398..6bd1070046 100644 --- a/terraform/state_add.go +++ b/terraform/state_add.go @@ -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, }, } diff --git a/terraform/state_add_test.go b/terraform/state_add_test.go index b2000b244b..f1d5e34581 100644 --- a/terraform/state_add_test.go +++ b/terraform/state_add_test.go @@ -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 {