{"record":{"id":"c9cd23edd657d4dc","repo":"puppetlabs/puppet","slug":"to-support-listing-resources-of-this-type-the-p","errorCode":null,"errorMessage":"To support listing resources of this type the '%{provider}' provider needs to implement an 'instances' class method returning the current set of resources. We recommend porting your module to the simpler Resource API instead: https://puppet.com/search/docs?keys=resource+api","messagePattern":"To support listing resources of this type the '%(.+?)' provider needs to implement an 'instances' class method returning the current set of resources\\. We recommend porting your module to the simpler Resource API instead: https://puppet\\.com/search/docs\\?keys=resource\\+api","errorType":"exception","errorClass":"Puppet::DevError","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider.rb","lineNumber":383,"sourceCode":"  # An implementation of this method should only cache the values of properties\n  # if they are discovered as part of the process for finding existing resources.\n  # Resource properties that require additional commands (than those used to determine existence/identity)\n  # should be implemented in their respective getter method. (This is important from a performance perspective;\n  # it may be expensive to compute, as well as wasteful as all discovered resources may perhaps not be managed).\n  #\n  # An implementation may return an empty list (naturally with the effect that it is not possible to query\n  # for manageable entities).\n  #\n  # By implementing this method, it is possible to use the `resources´ resource type to specify purging\n  # of all non managed entities.\n  #\n  # @note The returned instances are instance of some subclass of Provider, not resources.\n  # @return [Array<Puppet::Provider>] a list of providers referencing the system entities\n  # @abstract this method must be implemented by a subclass and this super method should never be called as it raises an exception.\n  # @raise [Puppet::DevError] Error indicating that the method should have been implemented by subclass.\n  # @see prefetch\n  def self.instances\n    raise Puppet::DevError, _(\"To support listing resources of this type the '%{provider}' provider needs to implement an 'instances' class method returning the current set of resources. We recommend porting your module to the simpler Resource API instead: https://puppet.com/search/docs?keys=resource+api\") % { provider: name }\n  end\n\n  # Creates getter- and setter- methods for each property supported by the resource type.\n  # Call this method to generate simple accessors for all properties supported by the\n  # resource type. These simple accessors lookup and sets values in the property hash.\n  # The generated methods may be overridden by more advanced implementations if something\n  # else than a straight forward getter/setter pair of methods is required.\n  # (i.e. define such overriding methods after this method has been called)\n  #\n  # An implementor of a provider that makes use of `prefetch` and `flush` can use this method since it uses\n  # the internal `@property_hash` variable to store values. An implementation would then update the system\n  # state on a call to `flush` based on the current values in the `@property_hash`.\n  #\n  # @return [void]\n  #\n  def self.mk_resource_methods\n    [resource_type.validproperties, resource_type.parameters].flatten.each do |attr|\n      attr = attr.intern","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider.rb#L365-L401","documentation":"Provider.instances is the abstract class method that enumerates existing system entities; it powers 'puppet resource <type>' listing, prefetching, and purge-style management via the resources metatype. The base implementation always raises Puppet::DevError, telling you to implement instances or port the provider to the Resource API. Seeing it means the selected provider for the type cannot list resources at all.","triggerScenarios":"Running puppet resource mytype on a custom type whose provider only implements instance methods; using resources { myresources: purge => true } for a type whose provider lacks instances; calling Provider.instances directly from Ruby tooling.","commonSituations":"Custom types written only for declared resources; third-party modules that never supported puppet resource; inventory tooling that enumerates types via puppet resource.","solutions":["Implement def self.instances in the provider: gather system state and return provider instances via new(name: n, ensure: :present, ...).","Or port the provider to the Puppet Resource API (pdk new provider), where instances is generated from the schema.","Do not use puppet resource or purging with types whose providers cannot enumerate."],"exampleFix":"# before (provider)\nPuppet::Type.type(:mything).provide(:ruby) do\n  # no self.instances -> puppet resource mything raises Puppet::DevError\nend\n\n# after\nPuppet::Type.type(:mything).provide(:ruby) do\n  def self.instances\n    Dir['/etc/mything/*'].map do |path|\n      new(name: File.basename(path), ensure: :present)\n    end\n  end\nend","handlingStrategy":"validation","validationCode":"def implements_instances?(provider_class)\n  provider_class.method(:instances).owner != Puppet::Provider\nend\n# skip listing when false\nexit 0 unless implements_instances?(Puppet::Type.type(:mything).provider(:ruby))","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Type.type(:mything).provider(:ruby).instances\nrescue Puppet::DevError => e\n  Puppet.err(\"mything provider cannot list resources: #{e.message}\")\n  []\nend","preventionTips":["Implement self.instances in every provider meant to support puppet resource or prefetching.","Gate inventory scripts on the provider actually overriding instances.","Consider the Puppet Resource API for new types - listing support comes for free."],"tags":["puppet","provider","instances","abstract-method","custom-provider"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}