Hey guys. I’m having issues with a custom resource. I created a custom resource in its own cookbook. In that custom resource I’m using a simple template. So I created another cookbook that depends on the cookbook with the custom resource. When I run chef it errors saying that it can’t find the template source. The error shows that it is looking for the template source in the second cookbook that depends on the resource rather than the custom resource cookbook. Is this normal?
In the cookbook with the custom resource, use a
cookbook property in the template resource, specifying that cookbook as the source of the template.
Ahh thanks I appreciate the help!
Because it is a custom resource, the default cookbook for the template is the cookbook the resource is being used in — not the cookbook where the custom resource resides. You have to get specific with the cookbook property, which is why it exists. If you want the user of the custom resource to have to provide a template, you can, and that is the default behaviour.
If on the other hand you specify the template location as the cookbook of the custom resource, and the user of the resource wants to override it, it is a bit trickier … but they still can using
edit_resource to provide an alternate location for the template. Or, in your custom resource, you can have
template_cookbook or similar as an optional property which you then use for the cookbook property for your template, so they can override it more easily that way, if that makes sense to do.
I think I had to explain that a dozen times, unsure that’s somewhere in http://learn.chef.io|learn.chef.io courses or not, but your explanation sounds a good addition to https://github.com/chef/chef-web-docs/blob/master/content/custom_resources.mds IMHO
We probably should have something like that there … wordsmithed a lot more than my hasty explanation, lol