The refactor for version 10 of this cookbook makes some major changes to the underlying method of operation of the cookbook to improve operation and maintainability.
In summary:
- Accumulator config hash initialisation is automatic upon initial access
- Accumulator config hash paths are automatically generated from the resource name
- Property enumeration is automatic so adding a property to resource will result in that property being added to the configuration Hash
- Most config resource functionality has been moved to the partially-abstract
_config_file
and_config_file_ldap
partial resources- Barring edge cases, all
config_*
resources inherit from these partials and contain only their properties load_current_value
has been implemented for all resources
- Barring edge cases, all
- The
extra_options
hash property has been added to allow the additional of arbitrary configuration options (all config resources) - Config files are now generated by the
inifile
andtoml-rb
gems so the templates are purely placeholders
Adding a new configuration item to an existing resource is as simple as adding the required item as a property to resource representing the section of the configuration file.
To add a new configuration section a config_
resource should be created where the name following the config_
prefix is the name of the configuration section to represent. Configuration items under the section are then added as properties to this resource.
The configuration resource must then inherit from the _config_base
partial template via the addition of
use 'partial/_config_file'
At the top of the resource declaration above the first property.
See a pre-existing resource for an example of this pattern.
If the name of the resource with the 'grafana_config_
prefix removed does not match the name of the configuration section or a nested configuration section is in use such as section.subsection
then the automatic configuration path can be overridden by the addition of the :resource_config_path_override
method.
After the last resource property declaration, add the following code with the array contents set to the config Hash path set as you would pass to Hash#dig to create the required configuration path. Multiple nested Hashes are supported.
def resource_config_path_override
%w(external_image_storage.s3).freeze
end
If an additional property must be added for the resource to function but the property is not relevant for the Grafana config file then these properties can be marked to be skipped by the enumerator by the creation of a :resource_config_properties_skip
method.
def resource_config_properties_skip
%i(host).freeze
end
There are some cases where a Grafana configuration property name either conflicts with one of the base properties (config_auth_ldap
property :config_file
) or is a name that is disallowed by Chef (config_external_image_storage
property :provider
). To work around this issue there is a property translation mechanism implemented that can be used to alias the chef property name to the Grafana property name and vice-versa.
This is performed by the creation of a :resource_config_properties_translate
method as shown below.
def resource_config_properties_translate
{
storage_provider: 'provider',
}.freeze
end