Question

I am doing my custom LWRP. But I have a doubt about it implementation.

I check into the bluepill, and I see that.

def load_current_resource
  @current_resource = Chef::Resource::BluepillService.new(new_resource.name)
  @current_resource.service_name(new_resource.service_name)

  Chef::Log.debug("Checking status of service #{new_resource.service_name}")

  determine_current_status!

  @current_resource
end

I see that in others cookbook and I want to do something like this.

def load_current_resource
   @current_resource = Chef::Resource::MyCustomLWRP.new(new_resource.name)
   @current_resource
end

But I can't find where I have to define Chef::Resource::MyCustomLWRP.

I want to do this with the goal of create an idempotent resource.

Was it helpful?

Solution

There are a number of steps you have to go through to create your own custom resource (LWRP). In summary it involves creating a file in a cookbooks resources directory and an identically named file in the providers directory.

The file you create in the resources directory defines (among other things) the actions and attributes which your custom resource can accept. The file you create in the providers directory provides implementations for each of the actions that are specified in the resources file.

The name of resource will be the cookbook name + the file name without the rb extension.

For more details, there is a great tutorial here: http://dougireton.com/blog/2012/12/31/creating-an-lwrp/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top