DEV Community

Bogdan “Bodo” Dumitrescu
Bogdan “Bodo” Dumitrescu

Posted on

Stop Wrestling with Config Files: A DevOps Guide to Sanity with Konfigo

Konfigo

As a DevOps engineer, you've probably felt the pain of managing configuration files. You've got JSON, YAML, TOML, .env files, and maybe even some custom formats you'd rather not talk about. You're juggling configs for different environments (dev, staging, prod), and trying to keep everything in sync is a nightmare. What if I told you there's a better way?

Enter Konfigo, a powerful command-line tool that's about to become your new best friend.

What is Konfigo? 🤔

Konfigo is a versatile configuration management tool that helps you streamline your entire configuration workflow. It reads various configuration file formats, merges them intelligently, and processes the combined data against a user-defined schema for validation, transformation, and even batch output generation.

Think of it as a Swiss Army knife for your configuration files. 🇨🇭

Here are some of the key features that make Konfigo a game-changer for DevOps:

  • Multi-Format Support: JSON, YAML, TOML, and .env files are all supported. No more converting files by hand!
  • Flexible Merging: Intelligently merges multiple configuration sources, respecting order and immutability rules.
  • Powerful Schema Processing:
    • Variable Substitution: Inject dynamic values from environment variables, dedicated variable files, or schema defaults.
    • Data Generation: Create new configuration values (e.g., concat, timestamp, random, id).
    • Data Transformation: Modify keys and values (e.g., renameKey, changeCase, addKeyPrefix, addKeySuffix, deleteKey, trim, replaceKey, setValue).
    • Data Validation: Enforce rules (required, type, min, max, minLength, enum, regex).
  • Batch Processing: Use the konfigo_forEach directive in a variables file to generate multiple tailored configuration outputs from a single schema and run.
  • Environment Variable Integration: Override any configuration value directly using environment variables.

Why Should a DevOps Person Care? 🤷‍♀️

Okay, so Konfigo has a lot of features. But how does it actually make your life easier?

Tame the Multi-Headed Hydra of Configuration Formats

Let's say you have a base configuration in YAML, but your production environment requires some overrides from a .env file. With Konfigo, you can merge them with a single command:

konfigo -s base.yaml,prod.env -oy
Enter fullscreen mode Exit fullscreen mode

No more writing custom scripts to parse and merge different formats. Konfigo handles it all for you.

Automate Your Configuration Workflow

You can integrate Konfigo into your CI/CD pipelines to generate environment-specific configurations on the fly. For example, you can have a base configuration and then apply environment-specific overrides from different files.

Here's a conceptual example of how you might use Konfigo in a CI/CD pipeline:

- name: Generate production config
  run: konfigo -s config.yaml,overrides/production.yaml -of generated/config.production.json
- name: Deploy to production
  run: ./deploy.sh generated/config.production.json
Enter fullscreen mode Exit fullscreen mode

Prevent Configuration Drift

Configuration drift is a major source of headaches in any infrastructure. With Konfigo's schema validation, you can enforce a consistent structure and set of rules for your configurations.

For example, you can create a schema that requires a specific key to be present, or that a value must be a number within a certain range. If a configuration doesn't match the schema, Konfigo will throw an error, and you can catch the problem before it ever reaches production.

Dynamic Configurations are Your Friend

Stop hardcoding values in your configuration files! With Konfigo, you can use variables and data generation to create dynamic configurations.

For example, you can use an environment variable to set the database host, or you can use the timestamp generator to add a build timestamp to your configuration.

konfigo -s config.json -S schema.yml -V staging-vars.yml -of staging_config.json
Enter fullscreen mode Exit fullscreen mode

Simplify Complex Setups

If you're managing configurations for a microservices architecture or a multi-tenant application, you know how complex it can get. Konfigo's batch processing feature can help you simplify this.

You can create a template configuration and then use a variables file to generate multiple tailored configurations for each service or tenant.

A Simple Example

Let's look at a simple example of how Konfigo can be used to validate and transform a configuration file.

Input (config.json):

{
  "database": {
    "host": "localhost",
    "port": 5432
  },
  "feature_flags": {
    "new_dashboard": true
  }
}
Enter fullscreen mode Exit fullscreen mode

Schema (schema.yaml):

schema:
  properties:
    database:
      properties:
        host:
          type: string
        port:
          type: integer
          validation:
            - type: min
              value: 1024
    feature_flags:
      properties:
        new_dashboard:
          type: boolean
  transformations:
    - type: addKeyPrefix
      path: database
      value: db_
  required:
    - database
Enter fullscreen mode Exit fullscreen mode

Command:

konfigo -s config.json -S schema.yaml -oj
Enter fullscreen mode Exit fullscreen mode

Output:

{
  "db_database": {
    "host": "localhost",
    "port": 5432
  },
  "feature_flags": {
    "new_dashboard": true
  }
}
Enter fullscreen mode Exit fullscreen mode

In this example, Konfigo does two things:

  1. Validates the input to ensure that database.port is at least 1024.
  2. Transforms the input by adding the prefix db_ to the database key.

Ready to Give it a Try? 🚀

I've only scratched the surface of what Konfigo can do. If you're tired of wrestling with configuration files, I highly recommend giving it a try.

Let me know what you think in the comments below! 👇

Top comments (0)