How to make your charm configurable

Charms should always deploy with considered defaults that enable the application to start with as little friction as possible. That said, there are cases when it may be prudent to expose application configuration to the administrator. This should be a point of consideration for the charm developer; configuration is one of the few interfaces a charm developer can expose to an administrator, and thus it should be carefully designed.

One way to think about this is what are the necessary configuration options to configure the service the application provides. If you find the configuration specification too restrictive, and find yourself passing in lots of base64 encoded structures, you may want to rethink the approach.

Contents:

  1. Define a configuration option
  2. Define configuration event handlers

Define a configuration option

In the config.yaml file of the charm, under options, add a configuration definition.

See more: File config.yaml > options

Define configuration event handlers

In your charm.py file, set up an observer for the config-changed event and pair it with an event handler.

See more: Event config-changed

Pro tip: It’s a good idea to validate values, as Juju only checks that the type is valid.


Last updated 3 months ago.