Announcing Config Builder

Malcolm Matalka avatar

Malcolm Matalka

Cover for Announcing Config Builder

Introduction

In today’s fast-moving cloud-native world, static infrastructure configurations aren’t always enough. Whether you’re scaling dynamically, managing multiple environments, or integrating with external APIs, being able to generate configurations on the fly can be a game-changer.

That’s where Terrateam’s Config Builder comes in. By enabling dynamic configuration generation at runtime, Terrateam allows you to adapt and respond to your infrastructure needs in real time.

Why Dynamic Configuration Generation?

In today’s infrastructure landscape, managing static configurations can be limiting, especially as teams scale and evolve. With Terrateam, we recognize that modern teams need flexibility. Infrastructure setups often depend on dynamic factors like environments, external data, and interdependencies across services. Manually adjusting configurations for each scenario slows teams down.

Terrateam’s Config Builder empowers teams to automate these processes, allowing configurations to be generated dynamically at runtime. This ensures your infrastructure is responsive to changing conditions without the need for constant manual updates, keeping your deployments smooth and efficient.

Whether it’s handling different environments, integrating real-time data from external APIs, or managing complex dependencies between services, Terrateam’s config builder lets you automate with ease, helping teams modernize the way they build and manage infrastructure.

Getting Started with Config Builder

The Config Builder is enabled with just a few lines of configuration in your .terrateam/config.yml file. From there, you can write a script to generate your dynamic configuration. Here’s an example of generating different configurations based on the environment:

.terrateam/config.yml
config_builder:
enabled: true
script: |
#! /usr/bin/env bash
if [[ $ENV == "production" ]]; then
# Generate production configuration
else
# Generate development configuration
fi

In this example, the script checks the $ENV environment variable and generates either a production or development configuration.

Real-World Use Cases

Let’s dive into some practical applications of the config_builder and how it can streamline your Terraform workflows.

Dynamic Configuration Based on Environment

As shown in the previous example, you can easily generate different configurations depending on whether you’re in a production or development environment. This approach is particularly useful in CI/CD pipelines, where different environments need distinct Terraform plans.

Fetching Configuration from an External API

Sometimes, your configuration depends on external data. Perhaps a system that provides networking info, or an API that delivers environment-specific variables. The Config Builder makes it easy to fetch this data dynamically and use it in your configuration.

.terrateam/config.yml
config_builder:
enabled: true
script: |
#! /usr/bin/env bash
CONFIG=$(curl -s https://api.example.com/config)
echo ${CONFIG}

By using an external API, your configuration is automatically adjusted based on the latest available data.

Handling Multi-Tenancy with Dynamic Configuration

In multi-tenant systems, different customers or tenants might need customized configurations. Instead of managing multiple static files, the Config Builder can help you dynamically generate configurations for each tenant.

.terrateam/config.yml
config_builder:
enabled: true
script: |
#! /usr/bin/env bash
case $TENANT in
tenant1)
# Generate config for tenant1
;;
tenant2)
# Generate config for tenant2
;;
*)
echo "Unknown tenant"
exit 1
;;
esac

This approach allows you to dynamically create configurations based on the $TENANT environment variable.

Advanced Use Case: Managing Dependencies Dynamically

One of the most powerful use cases of Config Builder is managing dependencies between infrastructure components. In large-scale projects, you often have multiple directories and services that depend on each other. Manually tracking and updating dependencies can be error-prone and time-consuming. Let’s say you have multiple projects with services that depend on specific databases. You can use the Config Builder to dynamically set the dependency relationships between these components.

.terrateam/config.yml
config_builder:
enabled: true
script: |
${TERRATEAM_ROOT}/bin/deps

The script in bin/deps can read a YAML file that defines the dependencies between different services.

.terrateam/deps.yml
dirs:
projects/proj1/database1:
deps:
- projects/proj1/base
projects/proj1/database2:
deps:
- projects/proj1/base
projects/proj2/database1:
deps:
- projects/proj2/base
projects/proj2/database2:
deps:
- projects/proj2/base

This structure allows for dynamic dependency resolution based on real-time data and updates.

The script itself can then process these dependencies and apply them accordingly:

bin/deps
#! /usr/bin/env python3
import os
import sys
import json
import yaml
repo_config = json.load(sys.stdin)
with open(os.path.join(os.environ['TERRATEAM_ROOT'], '.terrateam', 'deps.yml')) as f:
deps = yaml.safe_load(f)
dep_dirs = deps.get('dirs', {})
for d in repo_config.get('dirs', {}):
if d in dep_dirs:
deps_list = dep_dirs[d].get('deps', [])
depends_on = ' or '.join(['dir:' + dir for dir in deps_list])
repo_config.setdefault('dirs', {})[d].setdefault('when_modified', {})['depends_on'] = depends_on
print(json.dumps(repo_config, indent=2))

With this setup, the Config Builder automatically manages the dependencies between projects, ensuring that services are deployed in the correct order.

Conclusion

At Terrateam, we believe that the future of infrastructure management is dynamic, scalable, and flexible. The Config Builder feature is just one way we are pushing forward the modern way teams build and manage their infrastructure, by making it adaptable to the ever-changing needs of cloud-native environments. Whether you’re managing multi-environment deployments, working with external data, or handling complex dependencies, Terrateam gives you the power to automate and streamline your Terraform workflows effortlessly.

As infrastructure complexity grows, traditional static configurations can no longer keep up. With Terrateam, you’re equipped with the tools to dynamically adapt and evolve your infrastructure, ensuring your team stays ahead of the curve and can focus on building the future, rather than managing configurations.

Infrastructure as Code. Optimized.

Ready to get started?

Experience powerful infrastructure orchestration, seamlessly integrated with GitHub.