def find_in_map(value):
    """If the value is a ^map macro, replace it with a Cloud Formation
    Formation ``Fn::FindInMap`` function, splitting up the period delimited
    reference. For example if a value is ``^map Foo.Bar.Baz`` it will be
    returned as ``dict({'Fn::FindInMap': ['Foo', 'Bar', Baz'})``.

    :param str value: The value to check for the map macro
    :rtype: str|dict
    :raises: ValueError

    """
    if value.startswith('^map '):
        ref = value[5:].split('.')
        if len(ref) != 3:
            raise ValueError('Invalid map reference: {}'.format(value[5:]))
        return {'Fn::FindInMap': ref}
    return value
