Skip to content
tezvyn:
Menu

Configuration as Code: Version Control for Your Settings

Source: Wikipedia: Infrastructure as codeMediumHow cards are made

Configuration as Code treats your system settings like source code: defined in files, versioned, and automatically applied. It's used to manage app settings or service credentials across environments, preventing manual errors.

Why it exists

Manually configuring systems is slow, error-prone, and leads to "configuration drift," where each environment (dev, staging, production) becomes a unique, undocumented snowflake. This makes reproducing systems or tracking down environment-specific bugs nearly impossible. Configuration as Code was created to solve this by making configuration automated, repeatable, and auditable.

The mental model

Treat your system's configuration not as a series of clicks in a UI or commands typed into a shell, but as a set of machine-readable definition files. These files become the single source of truth for how your software and infrastructure should be configured. Just like application code, this configuration code lives in a version control system like Git, giving you a full history of every change.

How it works

Instead of logging into a server to change a setting, you modify a definition file (e.g., a YAML or JSON file). You then commit this change to your repository. An automated process, often part of a CI/CD pipeline, detects the change and applies it to the target systems. This process can be imperative (running a script that executes steps to reach the new state) or, more commonly, declarative (defining the desired end state and letting a tool figure out how to get there).

When to use it

CaC is essential for managing settings across multiple servers or environments. It's perfect for handling application settings, feature flags, database connection strings, or middleware configurations. Any time you need to ensure consistency and repeatability between your development, testing, and production environments, CaC is the right approach. It is a core practice in modern DevOps and SRE.

When not to use it

For a single, simple application with a static configuration that rarely changes, the overhead of setting up a CaC workflow might not be justified. More importantly, CaC is not a secrets management solution. Storing sensitive data like passwords or API keys directly in configuration files is a major security risk, even in private repositories. These should be managed with a dedicated secrets vault.

One canonical example

A web application needs a different database connection string for development and production. Instead of manually setting an environment variable on the production server, you define it in configuration files. A dev.yaml might have database_url: "user:pass@localhost/dev_db" while a prod.yaml has database_url: "${PROD_DB_URL}". The production value is a reference to a secret managed by a vault. When deploying to production, the CI/CD system pulls the secret from the vault and injects it, applying the configuration defined in prod.yaml.

Interview question

What is a primary benefit of implementing Configuration as Code?

  • a.It provides a version-controlled, repeatable, and consistent way to manage system settings across environments.Correct
  • b.It serves as the primary secure storage solution for sensitive data like API keys and database credentials.
  • c.It completely automates all system administration tasks, removing the need for human intervention.
  • d.It is mainly designed for managing application source code changes and dependencies, not infrastructure.
Why?

Configuration as Code's core purpose is to ensure consistency and repeatability of system settings across different environments by treating them as version-controlled files. While it involves automation, it does not completely automate all system administration tasks. It is explicitly stated that CaC is not a secrets management solution; sensitive data should be handled by dedicated vaults.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on mlops — each one lists the topics its interview covers.

See open roles