While writing custom resources in chef we define attributes, their type, their default value and whether they are mandatory to be specified or not, e.g.
attribute :plugin, kind_of: String, required: true
attribute :after_plugin, kind_of: String, required: false, :default => 'pam_unix.so'
Suppose I need to take an attribute that is a Hash like
attribute :after, kind_of: Hash, required: false, :default => {:search_interface => nil, :search_control => nil, :search_plugin => nil}
Here I have mentioned required: false
which means it is not mandatory for user to provide the Hash.
I need to specify that if the Hash is given, then the :search_interface
is mandatory
How can I achieve that?
When defining attribute (now named property), you can define callbacks that validate the user input.
See https://github.com/chef/chef/blob/cb4ee84e418164e8d2e85147efad711a42ff2799/lib/chef/resource/chef_gem.rb#L28 for an example.
In your case, you could write: