Search code examples
rubypuppet

Access resource type in implementation of Puppet custom resource type


I am implementing a custom resource type in Puppet 4.8.2. I would like the implementation of its provider to have access to its resource type. The Puppet source code indicates that a Puppet::Provider has these attribute accessors:

attr_accessor :resource_type
attr_accessor :resource

But when I print their values in my provider like so

Puppet::Type.type(:my_type).provide(:my_provider, :parent => Puppet::Provider) do
  # ...

  def my_property
     r = @resource
     rt = @resource_type
     notice("resource #{r} resource_type #{rt}")
     # ...
  end
end

it appears as if @resource has a value (of the form My_type[TITLE]) but @resource_type does none.

How can a provider (i.e. Puppet::Provider) access its resource type (i.e. Puppet::Type)?


Solution

  • @resource.type (instead of @resource_type) apparently does work.