Arthur Barr
Arthur Barr

Reputation: 648

Should a Chef custom resource use attributes as default property values?

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?

Upvotes: 2

Views: 1439

Answers (1)

coderanger
coderanger

Reputation: 54181

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.

Upvotes: 3

Related Questions