Chef11 lwrp issue with chef13


With Chef 11 we had (and still have) in providers:
def load_current_resource
@current_resource =
# …

I want to make my cookbooks compatible both with Chef 11 and later versions. But with Chef 13 I have an error that constant Chef::Resource::MyCookbookMyRes is not defined.

if I do ‘my_cookbook_my_res(‘foo’).class’ in chef-shell, it shows weird (and useless)

Custom resource my_res from cookbook my_cookbook

So the question: how to rewrite load_current_resource so it works both with Chef 11 and newer versions?

1 Like

Replying myself:
Chef::Resource.resource_for_node(@new_resource.declared_type, run_context.node)

Better answer

@current_resource =

Indeed, this should work with any chef version.

I’ve been looking for the right way to update these old custom resources—tyvm.