2
votes

Should a Chef custom resource use Chef attributes as default property values? I can see several options here:

  1. Have a pure library cookbook, with just custom resources (or LWRPs) which are only ever configured by someone writing a recipe using the Chef DSL.
  2. Have a library cookbook where the default values for properties can come from Chef attributes. This allows users to set certain values on the Chef server, as long as there's a recipe using the resources in question.
  3. Have a cookbook which provides custom resources, but has a default recipe which uses Chef attributes to fill in all the values. i.e. it's only the recipe that uses the attributes. In this case, the recipe (and attributes) could be in a separate cookbook, but it seems convenient to make it all in one cookbook.

What's the best practice here?

1
common practice being the wrapper cookbook to override attributes, there's no 'best' practice here IMHO. - Tensibai

1 Answers

3
votes

I go with option 3: https://github.com/poise/poise-monit/blob/master/chef/recipes/default.rb#L17-L22

I will sometimes use node attributes directly in resources or providers if it is something that has to be truly global, but I can only think of a handful of cases where that has been the case.