def BuildTargetConfigFromManifest(client,
                                  messages,
                                  project_id,
                                  deployment_id,
                                  manifest_id,
                                  properties=None):
    """Construct a TargetConfig from a manifest of a previous deployment.

  Args:
    client: Deployment Manager v2 API client.
    messages: Object with v2 API messages.
    project_id: Project for this deployment. This is used when pulling the
        the existing manifest.
    deployment_id: Deployment used to pull retrieve the manifest.
    manifest_id: The manifest to pull down for constructing the target.
    properties: Dictionary of properties, only used if the manifest has a
        single resource. Properties will override only. If the manifest
        has properties which do not exist in the properties hash will remain
        unchanged.

  Returns:
    TargetConfig containing the contents of the config file and the names and
    contents of any imports.

  Raises:
    HttpException: in the event that there is a failure to pull the manifest
        from deployment manager
    ManifestError: When the manifest being revived has more than one
        resource
  """
    try:
        manifest = client.manifests.Get(
            messages.DeploymentmanagerManifestsGetRequest(
                project=project_id,
                deployment=deployment_id,
                manifest=manifest_id,
            ))
        config_file = manifest.config
        imports = manifest.imports
    except apitools_exceptions.HttpError as error:
        raise api_exceptions.HttpException(error)

    # If properties were specified, then we need to ensure that the
    # configuration in the manifest retrieved has only a single resource.
    if properties:
        config_yaml = yaml.load(config_file.content)
        if len(config_yaml['resources']) != 1:
            raise exceptions.ManifestError(
                'Manifest reuse with properties requires '
                'there only be a single resource.')
        single_resource = config_yaml['resources'][0]
        if 'properties' not in single_resource:
            single_resource['properties'] = {}
        existing_properties = single_resource['properties']
        for key, value in six.iteritems(properties):
            existing_properties[key] = value
        config_file.content = yaml.dump(config_yaml)

    return messages.TargetConfiguration(config=config_file, imports=imports)
  def Run(self, args):
    """Run 'manifests describe'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      The requested manifest.

    Raises:
      HttpException: An http error response was received while executing api
          request.
    """
    manifest = args.manifest
    if not manifest:
      try:
        deployment = self.client.deployments.Get(
            self.messages.DeploymentmanagerDeploymentsGetRequest(
                project=dm_base.GetProject(),
                deployment=args.deployment
            )
        )
      except apitools_exceptions.HttpError as error:
        raise exceptions.HttpException(error)

      manifest = dm_api_util.ExtractManifestName(deployment)
      if not manifest:
        raise dm_exceptions.ManifestError(
            'The deployment [%s] does not have a current manifest. '
            'Please specify the manifest name.' % args.deployment)

    try:
      return self.client.manifests.Get(
          self.messages.DeploymentmanagerManifestsGetRequest(
              project=dm_base.GetProject(),
              deployment=args.deployment,
              manifest=manifest,
          )
      )
    except apitools_exceptions.HttpError as error:
      raise exceptions.HttpException(error, dm_api_util.HTTP_ERROR_FORMAT)