Chef11 lwrp issue with chef13

HI,

With Chef 11 we had (and still have) in providers:
def load_current_resource
@current_resource = Chef::Resource::MyCookbookMyRes.new(@new_resource.name)
# ...
end

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)
.new(@new_resource.name)

Better answer

@current_resource = new_resource.class.new(new_resource.name)
2 Likes

Indeed, this should work with any chef version.

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