  def _FindResourceByName(
      self,
      resources: Dict[str, ComputeResource],
      name: str,
      zone: Optional[str] = None,
      region: Optional[str] = None
  ) -> ComputeResource:
    """A helper function for finding compute resources by name.

    The resources can be zonal or regional.

    Args:
      resources: A dict of resources with resource IDs as keys and resource
        objects as values.
      name: The name of the resource to find.
      zone: The zone containing the resource.
      region: The region containing the resource.

    Returns:
      A subclass of 'compute_base_resource.GoogleComputeBaseResource' depending
        on the resource type.

    Raises:
      ValueError: If both zone and region is provided.
      ResourceNotFoundError: If the resource name is not found in resources.
      AmbiguousIdentifierError: If name matches multiple resources.
    """
    if zone and region:
      raise ValueError(
          'The resource must be either zonal or regional: '
          '_FindResourceByName is called with a zone and a region.')

    if zone:
      matches = [resource for resource in resources.values()
                if resource.name == name and resource.zone == zone]
    elif region:
      matches = [resource for resource in resources.values()
                if resource.name == name and resource.region == region]
    else:
      matches = [resource for resource in resources.values()
                 if resource.name == name]

    if not matches:
      raise errors.ResourceNotFoundError(
        f'Resource {name} was not found in project {self.project_id}',
        __name__)
    if len(matches) > 1:
      location : List [str] = [
          resource.zone or resource.region or '_' for resource in matches]
      raise errors.AmbiguousIdentifierError(
          f'Multiple resources found matching {name} in zones/regions '
          f'{", ".join(location)} in project {self.project_id}. Either '
          f'provide a resource ID or a zone argument.', __name__)

    return matches.pop()
A helper function for finding compute resources by name.

The resources can be zonal or regional.

Args:
resources: A dict of resources with resource IDs as keys and resource
objects as values.
name: The name of the resource to find.
zone: The zone containing the resource.
region: The region containing the resource.

Returns:
A subclass of 'compute_base_resource.GoogleComputeBaseResource' depending
on the resource type.

Raises:
ValueError: If both zone and region is provided.
ResourceNotFoundError: If the resource name is not found in resources.
AmbiguousIdentifierError: If name matches multiple resources.
libcloudforensics/providers/gcp/internal/compute.py