code: func NewLegacyResourceInstanceAddress(addr addrs.AbsResourceInstance) *ResourceAddress {
  	ret := &ResourceAddress{
  		Type: addr.Resource.Resource.Type,
  		Name: addr.Resource.Resource.Name,
  	}
  
  	switch addr.Resource.Resource.Mode {
  	case addrs.ManagedResourceMode:
  		ret.Mode = config.ManagedResourceMode
  	case addrs.DataResourceMode:
  		ret.Mode = config.DataResourceMode
  	default:
  		panic(fmt.Errorf("cannot shim %s to legacy config.ResourceMode value", addr.Resource.Resource.Mode))
  	}
  
  	path := make([]string, len(addr.Module))
  	for i, step := range addr.Module {
  		if step.InstanceKey != addrs.NoKey {
  			// At the time of writing this can't happen because we don't
  			// ket generate keyed module instances. This legacy codepath must
  			// be removed before we can support "count" and "for_each" for
  			// modules.
  			panic(fmt.Errorf("cannot shim module instance step with key %#v to legacy ResourceAddress.Path", step.InstanceKey))
  		}
  
  		path[i] = step.Name
  	}
  	ret.Path = path
  
  	if addr.Resource.Key == addrs.NoKey {
  		ret.Index = -1
  	} else if ik, ok := addr.Resource.Key.(addrs.IntKey); ok {
  		ret.Index = int(ik)
  	} else {
  		panic(fmt.Errorf("cannot shim resource instance with key %#v to legacy ResourceAddress.Index", addr.Resource.Key))
  	}
  
  	return ret
  }
docs: // NewLegacyResourceInstanceAddress creates a ResourceAddress from a new-style
  // addrs.AbsResource value.
  //
  // This is provided for shimming purposes so that we can still easily call into
  // older functions that expect the ResourceAddress type.