There are a lot of specifics but the overall pattern we use is "wrap and extend". The general idea is to make a cookbook that depends on the community cookbook, usually named mycompany_originalthing
, and then make recipes in that which call include_recipe 'originalthing::whatever'
but with either more stuff added before/after or with calls to things like edit_resource
to change resources. Avoid edit_resource
when possible since it leads to brittle code, but it is there if you need it. You can also use wrapper cookbooks to set attributes, subclass or wrap custom resources, and so on.
For the specific case of "I need to tweak a template in a community recipe" it would look like this:
include_recipe 'original::whatever'
edit_resource!(:template, '/path/to/something') do
source 'mytemplate.erb'
cookbook 'mycompany_original'
end
You can find more details about edit_resource
and friends at https://coderanger.net/rewind/
With cookbooks based around custom resources instead of recipes, things can get more complex but the specifics depend a lot on the how exactly the cookbook you are extending is written.