sous-chefs / users

Development repository for the users cookbook
https://supermarket.chef.io/cookbooks/users
Apache License 2.0
138 stars 218 forks source link

Allows `users` to be unset. #450

Closed Fuuzetsu closed 3 years ago

Fuuzetsu commented 3 years ago

:person_frowning: Problem Statement

We've been creating groups like this:

  grp = data_bag_item('groups', name)

  users_manage grp['id'] do
    group_id grp['gid']
    action :create

This gets compiled to something like this (slightly redacted):

    users_manage("…") do
      action [:create]
      default_guard_interpreter :default
      declared_type :users_manage
      cookbook_name "…-users"
      recipe_name "production"
      group_id …
      group_name "…"
    end

This worked until 6.0.0. From 6.0.0, we're getting an error like this:

FATAL: NoMethodError: users_manage[…] (…) had an error: NoMethodError: undefined method `each' for nil:NilClass

It's easy to see why this happens: https://github.com/sous-chefs/users/blob/6.0.0/resources/manage.rb#L34

This is the line pointed to by a stack-trace (not included).

:grey_question: Possible Solution

It'd be quite nice if users was set to be empty collection if it is not defined. This would allow definitions like ours to keep working transparently.

:arrow_heading_up: Describe alternatives you've considered

We can set the cookbook version bound to < 6.0.0 or specify users to be an empty collection.

:heavy_plus_sign: Additional context

Not really a bug as we're jumping a major version but it seems low effort to make it Just Work™, hence a feature request.

ramereth commented 3 years ago

@Fuuzetsu please feel free to make a PR which addresses this and we can get it merged/released!