puppetlabs/puppet · error · ArgumentError

Could not find resource type '%{name}'

Error message

Could not find resource type '%{name}'

What it means

The `resources` metatype (used to purge or inspect all instances of a type) validates its namevar against the type registry: `Puppet::Type.type(name)` must resolve (lib/puppet/type/resources.rb:18). Unknown or misspelled type names — including custom types whose Ruby lib was never loaded into the compiling process — raise ArgumentError "Could not find resource type".

Source

Thrown at lib/puppet/type/resources.rb:18

# frozen_string_literal: true

require_relative '../../puppet'
require_relative '../../puppet/parameter/boolean'

Puppet::Type.newtype(:resources) do
  @doc = "This is a metatype that can manage other resource types.  Any
    metaparams specified here will be passed on to any generated resources,
    so you can purge unmanaged resources but set `noop` to true so the
    purging is only logged and does not actually happen."

  apply_to_all

  newparam(:name) do
    desc "The name of the type to be managed."

    validate do |name|
      raise ArgumentError, _("Could not find resource type '%{name}'") % { name: name } unless Puppet::Type.type(name)
    end

    munge(&:to_s)
  end

  newparam(:purge, :boolean => true, :parent => Puppet::Parameter::Boolean) do
    desc "Whether to purge unmanaged resources.  When set to `true`, this will
      delete any resource that is not specified in your configuration and is not
      autorequired by any managed resources. **Note:** The `ssh_authorized_key`
      resource type can't be purged this way; instead, see the `purge_ssh_keys`
      attribute of the `user` type."

    defaultto :false

    validate do |value|
      if munge(value)
        unless @resource.resource_type.respond_to?(:instances)
          raise ArgumentError, _("Purging resources of type %{res_type} is not supported, since they cannot be queried from the system") % { res_type: @resource[:name] }

View on GitHub (pinned to e227c27540)

Solutions

  1. Correct the name to the exact, singular, lowercase type name (user, package, group, mount)
  2. If it is a custom type, ensure the module is in the environment and pluginsync delivered lib/puppet/type/*.rb to the agent (run the agent once, check the plugin destination)
  3. For puppet apply, pass --modulepath so the custom type is autoloaded before compilation

Example fix

# before
resources { 'ssh_authorized_keys':
  purge => true,
}

# after
resources { 'ssh_authorized_key':
  purge => true,
}
Defensive patterns

Strategy: type-guard

Validate before calling

# fail fast in generated manifests
unless Puppet::Type.type(type_name.to_sym)
  raise ArgumentError, "resources: unknown type '#{type_name}'"
end

Type guard

def known_type?(name)
  !Puppet::Type.type(name.to_s.to_sym).nil?
end

Try / catch

begin
  Puppet::Type.type(:resources).new(name: 'users', purge: true)
rescue ArgumentError => e
  raise unless e.message.include?('Could not find resource type')
  # fix the name or load the module providing the type
end

Prevention

When it happens

Trigger: `resources { 'users': purge => true }` (plural typo; the type is `user`); referencing a custom type from a module not present in the environment; running `puppet apply` without the module on the modulepath; wrong capitalization of the type name.

Common situations: Typos like users/user, pkgs/package, ssh_authorized_keys (plural); module refactors that removed a type while manifests still purge it; agents/compilers missing pluginsynced custom type files after environment changes.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/14af07f27ad5b0b4. Report an issue: GitHub.