Open source Puppet documentation

Resource types are a special family of data types that behave differently from other data types. They are subtypes of the fairly abstract Resource data type. Resource references are a useful subset of this data type family.

In the Puppet language, there are never any values whose data type is one of these resource types. That is, you can never create an expression where $my_value =~ Resource evaluates to true. For example, a resource declaration — an expression whose value you might expect would be a resource — executes a side effect and then produces a resource reference as its value. A resource reference is a data type in this family of data types, rather than a value that has one of these data types.

In almost all situations, if one of these resource type data types is involved, it makes more sense to treat it as a special language keyword than to treat it as part of a hierarchy of data types. It does have a place in that hierarchy; it’s just complicated, and you don’t need to know it to do things in the Puppet language.

For that reason, the information on this page is provided for the sake of technical completeness, but learning it isn't critical to your ability to use Puppet successfully.

Basics

Puppet automatically creates new known data type values for every resource type it knows about, including custom resource types and defined types.

These one-off data types share the name of the resource type they correspond to, with the first letter of every namespace segment capitalized. For example, the file type creates a data type called File.

Additionally, there is a parent Resource data type. All of these one-off data types are more-specific subtypes of Resource.

Usage of resource types without a title

A resource data type can be used in the following places:
  • The resource type slot of a resource declaration.

  • The resource type slot of a resource default statement.

For example:
# A resource declaration using a resource data type:
File { "/etc/ntp.conf":
  mode  => "0644",
  owner => "root",
  group => "root",
}

# Equivalent to the above:
Resource["file"] { "/etc/ntp.conf":
  mode  => "0644",
  owner => "root",
  group => "root",
}

# A resource default:
File {
  mode  => "0644",
  owner => "root",
  group => "root",
}

Usage of resource types with a title

If a resource data type includes a title, it acts as a resource reference, which are useful in several places. For more information, see Resource and class references.

The <SOME ARBITRARY RESOURCE TYPE> data type

For each resource type mytype known to Puppet, there is a data type, Mytype. It matches no values that can be produced in the Puppet language. You can use parameters to restrict which values Mytype matches, but it still matches no values.

Parameters

The full signature for a resource-type-corresponding data type Mytype is:
Mytype[<RESOURCE TITLE>]
This parameter is optional.
Position Parameter Data type Default value Description
1 Resource title String nothing The title of some specific resource of this type. If provided, this turns this data type into a usable resource reference.
Examples:
File
The data type corresponding to the file resource type.
File['/tmp/foo']
A resource reference to the file resource whose title is /tmp/foo.
Type[File]
The data type that matches any resource references to file resources. This is useful for, for example, restricting the values of class or defined type parameters.

The Resource data type

There is also a general Resource data type, which all <SOME ARBITRARY RESOURCE TYPE> data types are more-specific subtypes of. Like the Mytype-style data types, it matches no values that can be produced in the Puppet language. You can use parameters to restrict which values Resource matches, but it still matches no values.

This is useful in the following uncommon circumstances:
  • You need to interact with a resource type before you know its name. For example, you can do some clever business with the iteration functions to re-implement the create_resources function in the Puppet language, where your lambda receives arguments telling it to create resources of some resource type at runtime.

  • Someone has somehow created a resource type whose name is invalid in the Puppet language, possibly by conflicting with a reserved word — you can use a Resource value to refer to that resource type in resource declarations and resource default statements, and to create resource references.

Parameters

The full signature for Resource is:
Resource[<RESOURCE TYPE>, <RESOURCE TITLE>...]
All of these parameters are optional. They must be listed in order; if you need to specify a later parameter, you must specify values for any prior ones.
Position Parameter Data type Default value Description
1 Resource type String or Resource nothing A resource type, either as a string or a Resource data type value. If provided, this turns this data type into a resource-specific data type. Resource[Mytype] and Resource["mytype"] are identical to the data type Mytype.
2 and higher Resource title String nothing The title of some specific resource of this type. If provided, this turns this data type into a usable resource reference or array of resource references. Resource[Mytype, "mytitle"] and Resource["mytype", "mytitle"] are identical to the data type Mytype["mytitle"].
Examples:
Resource[File]
The data type corresponding to the file resource type.
Resource[File, '/tmp/foo']
A resource reference to the file resource whose title is /tmp/foo.
Resource["file", '/tmp/foo']
A resource reference to the file resource whose title is /tmp/foo.
Resource[File, '/tmp/foo', '/tmp/bar']
Equivalent to [ File['/tmp/foo'], File['/tmp/bar'] ].
Type[Resource[File]]
A synonym for the data type that matches any resource references to file resources. This is useful for, for example, restricting the values of class or defined type parameters.
Type[Resource["file"]]
Another synonym for the data type that matches any resource references to file resources. This is useful for, for example, restricting the values of class or defined type parameters.

The Class data type

The Class data type is roughly equivalent to the set of Mytype data types, except it is for classes. Like the Mytype-style data types, it matches no values that can be produced in the Puppet language. You can use parameters to restrict which values Class matches, but it will matches no values.

Parameters

The full signature for Class is:
Class[<CLASS NAME>]
This parameter is optional.
Position Parameter Data type Default value Description
1 Class name String nothing The name of a class. If provided, this turns this data type into a usable class reference.
Examples:
Class["apache"]
class reference to class apache.
Type[Class]
The data type that matches any class references. This is useful for, for example, restricting the values of class or defined type parameters.

Related data types

The abstract Catalogentry data type is the supertype of Resource and Class. You can use Type[Catalogentry] as the data type for a class or defined type parameter that can accept both class references and resource references.

Back to top
The page rank or the 1 our of 5 rating a user has given the page.
The email address of the user submitting feedback.
The URL of the page being ranked/rated.