Skip to content

config0.yml

OpenTofu workflows via stacks are executed through a launch configuration file - config0/config0.yml .

Sections

These are the major sections in the yml file:

global 
   arguments
     <arg 1>
     <arg 2>
     <arg 3>
   ...
<automation category>:
   <stack alias configuration>:
         stack_name: <stack_name>
           arguments:
               <arg 1>
               <arg 2>
               <arg 3>
               ...

global arguments

Global arguments refer to variables that are provided to every stack within a project. These arguments drive the expression of the automation.

global:
  arguments:
    cloud_provider: aws
    region: us-east-1
    db_type: mysql
    sg_db_label: database
    sg_web_label: web
Field Description
<global/arguments> stack arguments(variables) for all stacks in project.

labels/selectors

Labels and selectors work in together to assign labels to resources and subsequently choose them for downstream operations. This labels/selectors combination is similar to what is used in Kubernetes clusters.

  • labels - are key/value pairs that are attached to created resources.

    In the example below, the first label general contains key,value:

    • environment -> dev
    • purpose -> test

    labels:
       general:
         environment: dev
         purpose: test
       infrastructure:
         cloud: aws
         product: vpc
         app_tier: networking
       vehicle:
         car: bmw
    
    As shown, the labels general, infrastructure, and vehicle will be applied to infrastructure resources like VPCs, subnets, security groups, and internet gateways.
    infrastructure:
       vpc:
           stack_name: config0-publish:::aws_vpc_and_security_group
           arguments:
             eks_cluster: eval-ed-eks
             vpc_name: eval-ed-vpc
             main_network_block: 10.30.0.0/16
             tier_level: "2"
             enable_nat_gateway: true
             single_nat_gateway: true
             enable_dns_hostnames: true
             reuse_nat_ips: true
             one_nat_gateway_per_az: false
             tags: "mongo,database,stateful"
           labels:
             - general
             - infrastructure
             - vehicle
    

  • selectors - are key/value pairs that are employed to query the Config0 database and retrieve matching resources.

    Other notable query parameters for metadata matchSelectors:

    • labels are key/value “labels” for resource db query
    • keys are specific key,value (not labels) used as part of the query.
    • params are additional params/conditions/special fields for the query. For example:
    • must_exist => True – the query must return at least a value
    • resource_type => The resource type to query for.

    An example of selector(s) definitions.

    metadata:   
      labels:
         general: 
           environment: dev
           purpose: eval-config0
         infrastructure:
           cloud: aws
           product: eks
      matchSelectors:
         network_vars:
           labels:
             environment: dev
             purpose: eval-config0
             area: network
             region: eu-west-1
             cloud: aws
         eks_info:
           keys:
             provider: aws
             region: eu-west-1
             aws_default_region: eu-west-1
           params:
             resource_type: eks
           labels:
             environment: dev
             purpose: eval-config0
             cloud: aws
    

    Selectors must be included for each stack - they are not global.

    infrastructure:
       rds:
           stack_name: config0-publish:::aws_rds
           arguments:
              vpc_name: selector:::vpc_info::name
              sg_id: selector:::sg_info::sg_id
              subnet_ids: selector:::subnet_info::subnet_id:csv
              rds_name: eval-ed-rds
              allocated_storage: 14
              db_name: app
           selectors:
             - vpc_info
             - sg_info
             - subnet_info
    

The selector query below:

<variable_name>:selector:::<selector_name>::<key_in_query>::<format>

For example:

  • vpc_name:selector::: vpc_info :: name
  • subnet_ids:selector::: subnet_info :: subnet_id :: csv

The variable vpc_name will be looked up through the selector vpc_info . The key name is return from the selector result. String is the default format.

The subnet_ids will be looked up through the selector subnet_info . The key subnet_id from results is returned. The format will be a string of subnet_ids separated by a comma – csv .

specify stacks

Parameterized stacks are driven by primarily through arguments and secondarily environmental variables. Since stacks are first class citizens, they are specified and configured as such:

automation category

  • the stacks are categorized by automation category in the yml configuration.
  • examples: infrastructure, build, and deploy.

stack alias

  • in each automation category, the stack is given an alias.
  • example: “ecr_repo” is an alias for stack name config0-publish:::ecr_repo.

stack name

  • the stack names are referenced by username, stack_name, and optionally version
  • <username>:::<stack_name>::<version>
    • latest version (most common)
      • config0-publish:::ec2_docker_host
    • release version (most known and stable)
      • config0-publish:::ec2_docker_host:0.0.1
    • auto-incrementing version (most simple)
      • config0-publish:::ec2_docker_host:5

arguments

  • variables used by the stack.
  • arguments drive the behavior of the stack.
#<automation_category>
#    <stack_alias_setup>
#        stack_name: <stack_name>
#        arguments:
#        ...
infrastructure:
   ecr_repo:
       stack_name: config0-publish:::ecr_repo
       arguments:
          name: flask_sample
   dockerhost:
       stack_name: config0-publish:::ec2_docker_host
       arguments:
          size: t2.micro
          disksize: 25

full example

The provided sample YAML file creates an EKS cluster using an existing VPC. This example provides end-to-end automation with a single entry point; specifically, the stack:

config0-publish:::aws_eks.

Full Example EKS Cluster with Existing VPC
global:
  arguments: 
    aws_default_region: eu-west-1
  metadata:   
    labels:
       general: 
         environment: dev
         purpose: eval-config0
       infrastructure:
         cloud: aws
         product: eks
    matchSelectors:
       network_vars:
         labels:
           environment: dev
           purpose: eval-config0
           area: network
           region: eu-west-1
           cloud: aws
       eks_info:
         keys:
           provider: aws
           region: eu-west-1
           aws_default_region: eu-west-1
         params:
           resource_type: eks
         labels:
           environment: dev
           purpose: eval-config0
           cloud: aws
infrastructure:
  eks:
    stack_name: config0-publish:::aws_eks
    arguments:
      vpc_name: selector:::network_vars::vpc_name
      vpc_id: selector:::network_vars::vpc_id
      # vpc with NAT, private_subnet_ids is more secure
      subnet_ids: selector:::network_vars::public_subnet_ids:csv
      sg_id: selector:::network_vars::bastion_sg_id
      eks_cluster: eval-config0-eks
      eks_cluster_version: 1.25
      publish_to_saas: true
      # vpc with NAT, private_subnet_ids is more secure
      eks_subnet_ids: selector:::network_vars::public_subnet_ids:csv
      eks_node_role_arn: selector:::eks_info::node_role_arn
      eks_node_capacity_type: ON_DEMAND
      eks_node_ami_type: AL2_x86_64
      eks_node_max_capacity: 1
      eks_node_min_capacity: 1
      eks_node_desired_capacity: 1
      eks_node_disksize: 25
      eks_node_instance_types: 
        - t3.medium
        - t3.large
      cloud_tags_hash:
        environment: dev
        purpose: eval-config0
    spec:
      serialization:
        to_base64:
          arguments:
            - cloud_tags_hash
    metadata:
      labels:
        - general
        - infrastructure
      matchSelectors:
        - network_vars
        - eks_info

    • version is optional.
    • version auto-incrementing like 1,2,3
    • version release version