chef-boneyard / chef-provisioning-aws

AWS driver and resources for Chef that uses the AWS SDK
Apache License 2.0
142 stars 121 forks source link

Error when using the machine resource in a LWRP #503

Closed bdrust closed 8 years ago

bdrust commented 8 years ago

I am writing an LWRP that uses the machine resource and getting the following error:

================================================================================
    Error executing action `setup` on resource 'machine_batch[default]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `chef_provisioning' for nil:NilClass`

The stack trace points here: /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-provisioning-aws-1.11.0/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb:50:in `get_id_from_managed_entry'

and here is the code:

def get_id_from_managed_entry
    if should_have_managed_entry?
      entry = managed_entry_store.get(self.class.managed_entry_type, name)
      if entry
        driver = self.driver
        if entry.driver_url != driver.driver_url
          # TODO some people don't send us run_context (like Drivers).  We might need
          # to exit early here if the driver_url doesn't match the provided driver.
          driver = run_context.chef_provisioning.driver_for(entry.driver_url)
        end
        [ driver, entry.reference[self.class.managed_entry_id_name], entry ]
      end
    end
  end

The issue is that the entry.driver_url is empty. The same code runs correctly from a recipe but fails inside the LWRP. Can someone tell me how to set the entry.driver_url inside the context of an LWRP?

bdrust commented 8 years ago

I found the problem. I was passing an empty subnet array.