diff --git a/terraform/state_add.go b/terraform/state_add.go index 79a67ced9..c7d45e039 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_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, }, } } diff --git a/terraform/state_add_test.go b/terraform/state_add_test.go index 33cf1fa83..b2000b244 100644 --- a/terraform/state_add_test.go +++ b/terraform/state_add_test.go @@ -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 {