terraform: unify on init addr
This commit is contained in:
parent
c324062645
commit
cb060f9063
|
@ -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 {
|
func stateAddFunc_Instance_Instance(s *State, addr *ResourceAddress, raw interface{}) error {
|
||||||
src := raw.(*InstanceState).deepcopy()
|
src := raw.(*InstanceState).deepcopy()
|
||||||
|
|
||||||
// Create the module up to this point
|
// Create the instance
|
||||||
path := append([]string{"root"}, addr.Path...)
|
instanceRaw, _ := stateAddInitAddr(s, addr)
|
||||||
mod := s.ModuleByPath(path)
|
instance := instanceRaw.(*InstanceState)
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Depending on the instance type, set it
|
// Depending on the instance type, set it
|
||||||
switch addr.InstanceType {
|
switch addr.InstanceType {
|
||||||
case TypePrimary:
|
case TypePrimary:
|
||||||
resource.Primary = src
|
*instance = *src
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("can't move instance state to %s", addr.InstanceType)
|
return fmt.Errorf("can't move instance state to %s", addr.InstanceType)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue