In Puppet, there are some differences between defined
and function
types when it comes to code encapsulation. In most cases, a defined type is best, but there are some situations where a function is more appropriate.
Use a defined type when:
- You need to retrieve the resource or its parameter via
puppetdb_query()
. - The containing code creates real resources.
- You need a specific wrapper for the code.
Use a function when:
- You need to return data from the code.
- You don't need to specify a resource name.
- You need a general wrapper for the code.
Additionally, functions are useful for transforming data, such as combining data from multiple sources or converting data from one format to another. Functions can also help to encapsulate complex or repetitive code, making your Puppet code easier to read and maintain.
Abstraction can also lead to entanglement, where different parts of the code become tightly coupled and difficult to modify or maintain.