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]
file
resource type.Resource[File, '/tmp/filename.ext']
file
resource whose title is /tmp/filename.ext
.Resource["file",
'/tmp/filename.ext']
file
resource whose title is /tmp/filename.ext
.Resource[File, '/tmp/filename.ext',
'/tmp/bar']
[ File['/tmp/filename.ext'],
File['/tmp/bar'] ]
.Type[Resource[File]]
file
resources.
This is useful for, for example, restricting the values of class or
defined type parameters.Type[Resource["file"]]
file
resources. This is useful for, for
example, restricting the values of class or defined type
parameters.