Custom resources
A resource is the basic unit that is managed by Puppet. Each resource has a set of attributes describing its state. Some attributes can be changed throughout the lifetime of the resource, whereas others are only reported back but cannot be changed, and some can only be set one time during initial creation.
A custom resource allows you to interact with something external. Three common use cases for this are:
Parsing a file
Running a command line tool
Communicating with an API
To gather information about a resource and to enact changes on it, Puppet requires a provider to implement
interactions. The provider can have parameters that influence its operation. To describe
all these parts to the infrastructure and the consumers, the
resource type defines all the metadata, including the list of the
attributes. The provider contains the code to get
and set
the system
state.
If you are starting from scratch, or want a simple method for writing types and providers, use the Resource API. Built on top of Puppet core, the Resource API makes the type and provider development easier, cheaper, safer, faster, and better. If you need to maintain existing code, need multiple providers, or need access to the catalog, use the old low-level types and providers method.
-
Develop types and providers with the Resource API
The recommended method to create custom types and providers is to use the Resource API, which is built on top of Puppet core. It is easier, faster, and safer than the old types and providers method. -
Low-level method for developing types and providers
You can define custom resource types for managing your infrastructure by defining types and providers. This original method has largely been replaced by the Resource API method, but you might already have a setup that uses this low-level method, or your situation might fall into one of the Resource API limitations.