Product SiteDocumentation Site

3.3. Resources & Types

The following terms defined live in category Resources & Types.
By grouping these terms together, the authors hope to shed some light on when something is a type, when it becomes an instantiated type, and when it is a resource. Also, we bring the term system resource to the table, hopefully making a sufficiently clear distinction between two different perspectives.

Type or Resource?

The terms type and resource are very closely aligned. It's very easy to mix them up and so that's what happens throughout the Puppet community. I'm not saying I know better, but there is subtle syntax differences:
When addressing a type, you do so in all lowercase characters (file { blabla).
When addressing a resource (a previously instantiated type), you do so capitalized (File["blabla).
resource
A resource is an instantiated type. Once a type is instantiated, we use the term resource to indicate the instantiation of the type has been successful. A resource, finally, is going to manage a system resource, but we cannot yet speak of a system resource as it is unsure whether the resource is real, realized, virtual or exported, and on which node it's going to be applied -if at all.
Not to be confused with a type or system resource.
See also: virtual resource, exported resource, realize
exported resource
exported resource
See also: realize, virtual resource
virtual resource
virtual resource
See also: realize, exported resource
system resource
A system resource is a real resource from the perspective of the node or Operating System instance. This means a system resource does not have to physically exist, and does not have to relate to anything physical. Mind that when we manage users on a box that runs directly on physical hardware, we're still not managing anything truly physical, are we?
When we want to start managing the web service on a node, we'd say we need to manage the system resource(s) controlling the web service (often httpd within classic style initscripts), resulting in a resource Service["httpd"] (of instantiated type service) with parameter ensure set to running and parameter enable set to true.
Not to be confused with a type or resource.
type
Types are used to create resources in, for example, a class or node manifest. A type may be a custom type, defined type or a plugin type.
custom type
See defined type.
defined type
A defined type is a type created at the Puppet application level, contrary to a native type. Defined types are created using the define keyword in a manifest.
A defined type can be instantiated multiple times, similar to a native type, as long as the resource ends up with a unique name, and the resources instantiated by the defined type conform to the set of rules applicable to the types used. For example, you cannot instantiate defined type foo twice by using foo { "bar": enable => true } twice. This violates the resource uniqueness constraint, and the second attempt to instantiate the defined type foo will fail.
You can, however, instantiate defined type foo twice by using different names:
foo { [
        "bar",
        "baz"
    ]:
}
Again, the types instantiated by the defined type foo will still need to obey the rules for these types. The following snippet will not work:
define foo() {
    file { "/tmp/file":
        content => "$name"
    }
}

foo { [
        "bar",
        "baz"
    ]:
}
This will not work, because resource File["/tmp/file"] is now defined twice.
What would work though, and this is also the power of defined types;
define foo() {
    file { "/tmp/$name":
        content => "$name"
    }
}

foo { [
        "bar",
        "baz"
    ]:
}
Now, both resources File["/tmp/bar"] and File["/tmp/baz"] can be applied to the system (and become true system resources).
native type
A type written in pure Ruby, and provided with the Puppet application.
See also: defined type, custom type, plugin type
plugin type
plugin type