def expand_groups(config_ids, maps):
    """
    Iterates over a list of container configuration ids, expanding groups of container configurations.

    :param config_ids: List of container configuration ids.
    :type config_ids: collections.Iterable[dockermap.map.input.InputConfigId | dockermap.map.input.MapConfigId]
    :param maps: Extended container maps.
    :type maps: dict[unicode | str, dockermap.map.config.main.ContainerMap]
    :return: Expanded MapConfigId tuples.
    :rtype: collections.Iterable[dockermap.map.input.InputConfigId]
    """
    for config_id in config_ids:
        if config_id.map_name == '__all__':
            c_maps = six.iteritems(maps)
        else:
            c_maps = (config_id.map_name, maps[config_id.map_name]),
        if isinstance(config_id, InputConfigId):
            instance_name = config_id.instance_names
        elif isinstance(config_id, MapConfigId):
            instance_name = (config_id.instance_name, )
        else:
            raise ValueError("Expected InputConfigId or MapConfigId tuple; found {0}."
                             "".format(type(config_id).__name__))
        for map_name, c_map in c_maps:
            if config_id.config_name == '__all__' and config_id.config_type == ItemType.CONTAINER:
                for config_name in six.iterkeys(c_map.containers):
                    yield MapConfigId(config_id.config_type, map_name, config_name, instance_name)
            else:
                group = c_map.groups.get(config_id.config_name)
                if group is not None:
                    for group_item in group:
                        if isinstance(group_item, MapConfigId):
                            yield group_item
                        elif isinstance(group_item, six.string_types):
                            config_name, __, instance = group_item.partition('.')
                            yield MapConfigId(config_id.config_type, map_name, config_name,
                                              (instance, ) if instance else instance_name)
                        else:
                            raise ValueError("Invalid group item. Must be string or MapConfigId tuple; "
                                             "found {0}.".format(type(group_item).__name__))
                else:
                    yield MapConfigId(config_id.config_type, map_name, config_id.config_name, instance_name)