# Chef11 lwrp issue with chef13

**URL:** <https://discourse.chef.io/t/chef11-lwrp-issue-with-chef13/12767>\
**Category:** Chef Infra (archive)\
**Created:** [March 14, 2018, 4:49pm UTC](https://discourse.chef.io/t/chef11-lwrp-issue-with-chef13/12767 "2018-03-14T16:49:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![375gnu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/375gnu/32/1463_2.png) [@375gnu](https://discourse.chef.io/u/375gnu)\
**Post date:** [March 14, 2018, 4:49pm UTC](https://discourse.chef.io/t/chef11-lwrp-issue-with-chef13/12767/1 "2018-03-14T16:49:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![375gnu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/375gnu/32/1463_2.png) [@375gnu](https://discourse.chef.io/u/375gnu)\
**Post date:** [March 14, 2018, 5:35pm UTC](https://discourse.chef.io/t/chef11-lwrp-issue-with-chef13/12767/2 "2018-03-14T17:35:14Z")

</div>

Replying myself:  
Chef::Resource.resource\_for\_node(@new\_resource.declared\_type, run\_context.node)  
.new(@new\_resource.name)

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [March 15, 2018, 3:44am UTC](https://discourse.chef.io/t/chef11-lwrp-issue-with-chef13/12767/3 "2018-03-15T03:44:42Z")

</div>

Better answer

```ruby
@current_resource = new_resource.class.new(new_resource.name)

```

---

<div class="post-metadata">

**Author:** ![375gnu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/375gnu/32/1463_2.png) [@375gnu](https://discourse.chef.io/u/375gnu)\
**Post date:** [March 15, 2018, 7:30am UTC](https://discourse.chef.io/t/chef11-lwrp-issue-with-chef13/12767/4 "2018-03-15T07:30:56Z")

</div>

Indeed, this should work with any chef version.

---

<div class="post-metadata">

**Author:** ![sabat](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sabat/32/1628_2.png) [@sabat](https://discourse.chef.io/u/sabat)\
**Post date:** [March 19, 2018, 6:00pm UTC](https://discourse.chef.io/t/chef11-lwrp-issue-with-chef13/12767/5 "2018-03-19T18:00:13Z")

</div>

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