# Stack Groups and Stacks

Configuration for CloudFormation stacks is placed into stacks directory. Each subdirectory inside the stacks directory is treated as a stack group. Configuration for a stack group can be given by placing a config.yml file into the stack group directory.

By nesting directories, a hierarchy of stack groups can be built. In this hierarchy, stack groups’ children inherit configuration from their parents and can also override parts or all of it. The stacks directory itself is the root stack group and all other stack groups are its children.

All other .yml files inside the stacks directory are treated as configuration files for actual CloudFormation stacks. The stacks inherit configuration from the stack group they belong to, and like the child stack groups, they too can override the configuration they inherit.

Use correct file extension

Takomo expects the file extension for configuration files to be .yml.

The purpose of stack groups is to provide common configuration for the stacks that belong to them. You can use them to model your infrastructure into logical groups, for example by region or by application tier.

# Example

Here is an example of what a Takomo project could look like. In the stacks directory we have a config.yml file that contains configuration shared between all stack groups and stacks.

Then, we have two stack groups for application environments: dev and prod. Both the environments contain two stacks which are defined in application.yml and vpc.yml files. The dev environment also has its own config.yml file for configuration shared only with its stacks.

CloudFormation templates for the stacks are found from the templates directory.

.
├─ stacks
|  ├- config.yml
|  ├- dev
|  |  ├- config.yml
|  |  ├- application.yml
|  |  └- vpc.yml
|  └- prod
|     ├- application.yml
|     └- vpc.yml
└- templates
   ├- application-template.yml
   └- vpc-template.yml

# Identifying Stack Groups and Stacks

Stack groups and stacks are identified by their path. The paths are like file paths in *nix file system where the stacks directory is the root directory. The path for the root stack group is /, and for any other stack group, it is the absolute file path to the stack group directory from the stacks directory.

The stack paths follow this same logic with one important difference. The path for a stack is the absolute file path to its configuration file from the stacks directory, appended with a region specifier, that is a forward slash followed by the stack’s region. The region specifier can be omitted if the stack has only one region.

Stack regions

A stack can have one or more regions. The regions are defined in the stack's configuration file, which means there can be more than one CloudFormation stack created from a single stack configuration file.

These paths are used in many places in Takomo’s configuration files, and also accepted as input arguments by many CLI commands. Whenever a command path is required, one can always use a stack group path or a stack path.

# Example

Let's continue from the previous example and say that the root stack configuration file stacks/config.yml specifies that all stacks should belong to region eu-west-1. Furthermore, let's say that the dev environment's stacks/dev/config.yml overrides the region to be us-east-1. With this configuration, stack and stack group paths would look like this:

.
├─ stacks                         # root stack group path: /
|  ├- config.yml                  
|  ├- dev                         # dev stack group path: /dev
|  |  ├- config.yml               
|  |  ├- application.yml          # dev application stack path: /dev/application.yml/us-east-1
|  |  └- vpc.yml                  # dev vpc stack path: /dev/vpc.yml/us-east-1
|  └- prod                        # prod stack group path: /prod
|     ├- application.yml          # prod application stack path: /prod/application.yml/eu-west-1
|     └- vpc.yml                  # prod vpc stack path: /prod/vpc.yml/eu-west-1
└- templates
   ├- application-template.yml
   └- vpc-template.yml
Last Updated: 6/26/2020, 8:25:21 PM