title: How can you access Chef LWRP attributes in a recipe
body: <p>With some of the default chef resources, it is possible to access some of their attributes after they have been called</p>
  
  <pre><code># recipes/default.rb
  f = file "/tmp/file_resource" do
    owner "root"
    group "root"
    mode "0755"
    action :create
  end
  
  log "Path to my file is #{f.path}" # outputs "/tmp/file_resource"
  </code></pre>
  
  <p>How can this be achieved in a custom LWRP (here is an example)</p>
  
  <pre><code># resources/default.rb
  actions :create
  default_action :create
  
  attribute :relative_path, :kind_of =&gt; String, :name_attribute =&gt; true
  attribute :full_path, :kind_of =&gt; String
  </code></pre>
  
  <p>In this provider, I am trying to update the property of <code>new_resource.full_path</code> to be equal to the path of the file resource</p>
  
  <pre><code># providers/default.rb
  action :create do
  
    f = file "/path/to/my/resource/#{new_resource.relative_path}" do
      owner "root"
      group "root"
      mode "0755"
      action :create
    end
  
    new_resource.full_path(f.path)
    new_resource.updated_by_last_action(f.updated_by_last_action?)
  end
  </code></pre>
  
  <p>However when I try to access <code>resource.full_path</code> in the recipe, it is <code>nil</code> rather than the expected <code>/path/to/my/resource/relative/path</code></p>
  
  <pre><code># recipes/default.rb
  resource = my_awesome_lwrp "relative/path" do
    action :create
  end
  
  log "Full path for my resource: #{resource.full_path}" # outputs "Full path for my resource:"
  </code></pre>
  
  <p>This example is rather contrived I know, the real world application/reason for this can be seen in the default resource/provider here <a href="https://github.com/peterjmit/chef-ssl-cert" rel="nofollow">https://github.com/peterjmit/chef-ssl-cert</a></p>