Integrate with other DevOps Tool

To integrate configirl framework with other programming language, or other DevOps tool, you need a intermediate to exchange data. You have several options:

  1. json file.
  2. environment variable.
  3. external store like AWS Parameter Store.

In this document, let’s use terraform, a famous Infrastructure as Code open source tool, to demonstrate the idea.

In terraform, you can define input variables. But it is not to write complex variable handling logic in terraform, since natively it is just a DSL (Domain Specified Language). But you can define some variables, and inject value from configirl into terraform.

The integration layer is simple. You just use configirl to initialize yoru config object, then duump into the terraform.tfvars.json file, which would be the variable input for terraform.

Code example:

config declaration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-

from configirl import ConfigClass, Constant, Derivable


class Config(ConfigClass):
    PROJECT_NAME = Constant(default="my_devops")
    PROJECT_NAME_SLUG = Derivable()

    @PROJECT_NAME_SLUG.getter
    def get_PROJECT_NAME_SLUG(self):
        return self.PROJECT_NAME.get_value().replace("_", "-")

    STAGE = Constant(default="dev")

    ENVIRONMENT_NAME = Derivable()

    @ENVIRONMENT_NAME.getter
    def get_ENVIRONMENT_NAME(self):
        return "{}-{}".format(self.PROJECT_NAME_SLUG.get_value(), self.STAGE.get_value())

    def is_prod_runtime(self):
        return False

    _version = "0.0.1"

config initialization:

# content of config_init.py
from .config import Config
from configirl import write_text

config = Config()

write_text("/path-to-terraform-dir/terraform.tfvars.json", config.to_json())

terraform integration:

python config_init.py
terraform apply