Resolve any security group names to the corresponding group ids

        With the context of a given network attached resource.

def resolve_group_names(self, r, target_group_ids, groups):
        """Resolve any security group names to the corresponding group ids

        With the context of a given network attached resource.
        """
        names = self.get_group_names(target_group_ids)
        if not names:
            return target_group_ids

        target_group_ids = list(target_group_ids)
        vpc_id = self.vpc_expr.search(r)
        if not vpc_id:
            raise PolicyExecutionError(self._format_error(
                "policy:{policy} non vpc attached resource used "
                "with modify-security-group: {resource_id}",
                resource_id=r[self.manager.resource_type.id]))

        found = False
        for n in names:
            for g in groups:
                if g['GroupName'] == n and g['VpcId'] == vpc_id:
                    found = g['GroupId']
            if not found:
                raise PolicyExecutionError(self._format_error((
                    "policy:{policy} could not resolve sg:{name} for "
                    "resource:{resource_id} in vpc:{vpc}"),
                    name=n,
                    resource_id=r[self.manager.resource_type.id], vpc=vpc_id))
            target_group_ids.remove(n)
            target_group_ids.append(found)
        return target_group_ids