Issue in Keep your Chef cookbooks up to date

I’m following the tracks/modules to learn chef.
Everything went well till now. I’m now at this course:

foodcritic . is okay
cookstyle . is okay

But the issue starts when I add deprecations_as_errors: true in the .kitchen.yml. I run kitchen converge and the kitchen converge seems not to fail but I get ‘warnings’.

Deprecated features used!
     Cloning resource attributes for apt_package[install libapache2 package] from prior resource
   Previous apt_package[install libapache2 package]: /tmp/kitchen/cache/cookbooks/custom_apache/recipes/default.rb:31:in `block in from_file'
   Current  apt_package[install libapache2 package]: /tmp/kitchen/cache/cookbooks/custom_apache/recipes/default.rb:31:in `block in from_file' at 1 location:
       - /tmp/kitchen/cache/cookbooks/custom_apache/recipes/default.rb:31:in `block in from_file'
      See for further details.

   Chef Client finished, 0/12 resources updated in 02 seconds
   Downloading files from <default-ubuntu-1604>
   Finished converging <default-ubuntu-1604> (0m3.60s).

Now I just ‘ignored’ this and went for the fix of the deprecated features.
I replace packages = %w( libapache2-modsecurity libapache2-mod-spamhaus ) with package %w( libapache2-modsecurity libapache2-mod-spamhaus ) but now kitchen converge even fails:

 Running handlers:
   [2018-02-25T15:05:30+00:00] ERROR: Running exception handlers
   Running handlers complete
   [2018-02-25T15:05:30+00:00] ERROR: Exception handlers complete
   Chef Client failed. 0 resources updated in 01 seconds
   [2018-02-25T15:05:30+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
   [2018-02-25T15:05:30+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
   [2018-02-25T15:05:30+00:00] ERROR: No resource, method, or local variable named `packages' for `Chef::Recipe "default"'
   [2018-02-25T15:05:30+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Converge failed on instance <default-ubuntu-1604>.  Please see .kitch

The code to fix the deprecation warning should be just the two lines listed:

# Install additional Apache packages.
package %w( libapache2-modsecurity libapache2-mod-spamhaus )

Given the error, you still have the word packages somewhere in your code and chef doesn’t know what to do with it.

True, the packages is still used below to loop through. I’ll check if I can fix this as a beginner. But this is a ‘bug’ in the tutorial I think

What I and the tutorial are saying is that you can replace lines 6 through 13 with just two lines. Pretty sure this isn’t a bug but if you share the code you’re using for the default recipe then we can help your sort it out.

The package provider supports multiple packages being installed with a single resource when given an array so you don’t have to do any looping.

You’re right, read it wrong and replaced only the first 2 lines. Thanks.