# LWRP to extends another cookbook LWRP

**URL:** <https://discourse.chef.io/t/lwrp-to-extends-another-cookbook-lwrp/6576>\
**Category:** Chef Infra (archive)\
**Created:** [May 14, 2015, 12:42pm UTC](https://discourse.chef.io/t/lwrp-to-extends-another-cookbook-lwrp/6576 "2015-05-14T12:42:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_Toraldo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/giovanni_toraldo/32/89_2.png) [@Giovanni\_Toraldo](https://discourse.chef.io/u/Giovanni_Toraldo)\
**Post date:** [May 14, 2015, 12:42pm UTC](https://discourse.chef.io/t/lwrp-to-extends-another-cookbook-lwrp/6576/1 "2015-05-14T12:42:24Z")

</div>

Hi,

I just want to define a new LWRP to define some different defaults for  
attributes of another LWRP.

Googling I’ve found this: [http://stackoverflow.com/a/20732016/547195](http://stackoverflow.com/a/20732016/547195)

And I’ve tried with: [https://gist.github.com/gionn/6497eefdf9121c832b0e](https://gist.github.com/gionn/6497eefdf9121c832b0e)

But I am getting a recipe compile error:

Chef::Exceptions::InvalidResourceSpecification  
You must specify `resource_name'! /tmp/gionn_chef/cookbooks/cd-infrastructure/definitions/my_docker_container.rb:4:in`initialize’

Any suggestions?

Thanks!

–  
Giovanni Toraldo  
[http://gionn.net](http://gionn.net)

---

<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:** [May 14, 2015, 8:50pm UTC](https://discourse.chef.io/t/lwrp-to-extends-another-cookbook-lwrp/6576/2 "2015-05-14T20:50:07Z")

</div>

On May 14, 2015, at 2:42 PM, Giovanni Toraldo [me@gionn.net](mailto:me@gionn.net) wrote:

> Hi,
> 
> I just want to define a new LWRP to define some different defaults for  
> attributes of another LWRP.
> 
> Googling I've found this: [How to extend a lightweight provider in Chef - Stack Overflow](http://stackoverflow.com/a/20732016/547195)
> 
> And I've tried with: [https://gist.github.com/gionn/6497eefdf9121c832b0e](https://gist.github.com/gionn/6497eefdf9121c832b0e)
> 
> But I am getting a recipe compile error:
> 
> Chef::Exceptions::InvalidResourceSpecification  
> You must specify `resource_name'! /tmp/gionn_chef/cookbooks/cd-infrastructure/definitions/my_docker_container.rb:4:in `initialize'
> 
> Any suggestions?

This is not possible with LWRPs for reasons that are both complicated and very boring. Short version? You need to copy-pasta at least some of the upstream LWRP and build a wrapper around it instead of subclassing.

--Noah

---

<div class="post-metadata">

**Author:** ![Giovanni\_Toraldo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/giovanni_toraldo/32/89_2.png) [@Giovanni\_Toraldo](https://discourse.chef.io/u/Giovanni_Toraldo)\
**Post date:** [May 14, 2015, 9:06pm UTC](https://discourse.chef.io/t/lwrp-to-extends-another-cookbook-lwrp/6576/3 "2015-05-14T21:06:54Z")

</div>

On Thu, May 14, 2015 at 10:50 PM, Noah Kantrowitz [noah@coderanger.net](mailto:noah@coderanger.net) wrote:

> This is not possible with LWRPs for reasons that are both complicated and very boring. Short version? You need to copy-pasta at least some of the upstream LWRP and build a wrapper around it instead of subclassing.

UGH.

An alternative could be to send a PR to the upstream cookbook with a  
bunch of new node attributes defined to be used as default values for  
the LWRP attributes?

Other suggestions?

--  
Giovanni Toraldo

> **[Home](https://gionn.net/)**
>
> A blog abouth tech, programming and my personal life, alive and kicking from 2005.

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [May 15, 2015, 1:01am UTC](https://discourse.chef.io/t/lwrp-to-extends-another-cookbook-lwrp/6576/4 "2015-05-15T01:01:06Z")

</div>

for temporary workaround, you can write a helper method that takes a lwrp  
name, and returns the lwrp objects (resource and provider) and you use that  
to decorate/compose your new lwrp. in short use LWRPBase.from\_file in your  
library and pass it the file path (available from run context).  
let us know if you need some code samples,  
cheers  
ranjib

On Thu, May 14, 2015 at 2:06 PM, Giovanni Toraldo [me@gionn.net](mailto:me@gionn.net) wrote:

> On Thu, May 14, 2015 at 10:50 PM, Noah Kantrowitz [noah@coderanger.net](mailto:noah@coderanger.net)  
> wrote:
> 
> > This is not possible with LWRPs for reasons that are both complicated  
> > and very boring. Short version? You need to copy-pasta at least some of the  
> > upstream LWRP and build a wrapper around it instead of subclassing.
> 
> UGH.
> 
> An alternative could be to send a PR to the upstream cookbook with a  
> bunch of new node attributes defined to be used as default values for  
> the LWRP attributes?
> 
> Other suggestions?
> 
> --  
> Giovanni Toraldo  
> [http://gionn.net](http://gionn.net)
