// NewInstanceInfo constructs an InstanceInfo from an addrs.AbsResourceInstance.
//
// InstanceInfo is a legacy type, and uses of it should be gradually replaced
// by direct use of addrs.AbsResource or addrs.AbsResourceInstance as
// appropriate.
//
// The legacy InstanceInfo type cannot represent module instances with instance
// keys, so this function will panic if given such a path. Uses of this type
// should all be removed or replaced before implementing "count" and "for_each"
// arguments on modules in order to avoid such panics.
//
// This legacy type also cannot represent resource instances with string
// instance keys. It will panic if the given key is not either NoKey or an
// IntKey.
NewInstanceInfo constructs an InstanceInfo from an addrs.AbsResourceInstance.

InstanceInfo is a legacy type, and uses of it should be gradually replaced
by direct use of addrs.AbsResource or addrs.AbsResourceInstance as
appropriate.

The legacy InstanceInfo type cannot represent module instances with instance
keys, so this function will panic if given such a path. Uses of this type
should all be removed or replaced before implementing "count" and "for_each"
arguments on modules in order to avoid such panics.

This legacy type also cannot represent resource instances with string
instance keys. It will panic if the given key is not either NoKey or an
IntKey.
// NewInstanceInfo constructs an InstanceInfo from an addrs . AbsResourceInstance . // // InstanceInfo is a legacy type and uses of it should be gradually replaced // by direct use of addrs . AbsResource or addrs . AbsResourceInstance as // appropriate . // // The legacy InstanceInfo type cannot represent module instances with instance // keys so this function will panic if given such a path . Uses of this type // should all be removed or replaced before implementing " count " and " for_each " // arguments on modules in order to avoid such panics . // // This legacy type also cannot represent resource instances with string // instance keys . It will panic if the given key is not either NoKey or an // IntKey .
func NewInstanceInfo(addr addrs.AbsResourceInstance) *InstanceInfo {
	path := make([]string, len(addr.Module))
	for i, step := range addr.Module {
		if step.InstanceKey != addrs.NoKey {
			panic("NewInstanceInfo cannot convert module instance with key")
		}
		path[i] = step.Name
	}
	id := fmt.Sprintf("%s.%s", addr.Resource.Resource.Type, addr.Resource.Resource.Name)
	if addr.Resource.Resource.Mode == addrs.DataResourceMode {
		id = "data." + id
	}
	if addr.Resource.Key != addrs.NoKey {
		switch k := addr.Resource.Key.(type) {
		case addrs.IntKey:
			id = id + fmt.Sprintf(".%d", int(k))
		default:
			panic(fmt.Sprintf("NewInstanceInfo cannot convert resource instance with %T instance key", addr.Resource.Key))
		}
	}
	return &InstanceInfo{
		Id:         id,
		ModulePath: path,
		Type:       addr.Resource.Resource.Type,
	}
}
func NewInstanceInfo ( addr addrs . AbsResourceInstance ) * InstanceInfo { path := make ( [ ] string , len ( addr . Module ) ) for i , step := range addr . Module { if step . InstanceKey != addrs . NoKey { panic ( " " ) } path [ i ] = step . Name } id := fmt . Sprintf ( " " , addr . Resource . Resource . Type , addr . Resource . Resource . Name ) if addr . Resource . Resource . Mode == addrs . DataResourceMode { id = " " + id } if addr . Resource . Key != addrs . NoKey { switch k := addr . Resource . Key . ( type ) { case addrs . IntKey : id = id + fmt . Sprintf ( " " , int ( k ) ) default : panic ( fmt . Sprintf ( " " , addr . Resource . Key ) ) } } return & InstanceInfo { Id : id , ModulePath : path , Type : addr . Resource . Resource . Type , } }
NewInstanceInfo constructs an InstanceInfo from an addrs.AbsResourceInstance.
NewInstanceInfo constructs an InstanceInfo from an addrs . AbsResourceInstance .
// We need an old-style []string module path for InstanceInfo. // This is a funny old meaning of "id" that is no longer current. It should // not be used for anything users might see. Note that it does not include // a representation of the resource mode, and so it's impossible to // determine from an InstanceInfo alone whether it is a managed or data // resource that is being referred to.