From cb060f906328101c4440cc92d97652f05e1dd163 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 Apr 2016 18:28:36 -0700 Subject: [PATCH] terraform: unify on init addr --- terraform/state_add.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/terraform/state_add.go b/terraform/state_add.go index 445ba2ab8..21a713e5d 100644 --- a/terraform/state_add.go +++ b/terraform/state_add.go @@ -127,30 +127,14 @@ func stateAddFunc_Resource_Resource(s *State, addr *ResourceAddress, raw interfa func stateAddFunc_Instance_Instance(s *State, addr *ResourceAddress, raw interface{}) error { src := raw.(*InstanceState).deepcopy() - // Create the module up to this point - path := append([]string{"root"}, addr.Path...) - mod := s.ModuleByPath(path) - if mod == nil { - mod = s.AddModule(path) - } - - // Create the resources - resourceKey := (&ResourceStateKey{ - Name: addr.Name, - Type: addr.Type, - Index: addr.Index, - }).String() - resource, ok := mod.Resources[resourceKey] - if !ok { - resource = &ResourceState{Type: addr.Type} - resource.init() - mod.Resources[resourceKey] = resource - } + // Create the instance + instanceRaw, _ := stateAddInitAddr(s, addr) + instance := instanceRaw.(*InstanceState) // Depending on the instance type, set it switch addr.InstanceType { case TypePrimary: - resource.Primary = src + *instance = *src default: return fmt.Errorf("can't move instance state to %s", addr.InstanceType) }