CostFormation Syntax & YAML

Dimensions are implemented via CloudZero’s proprietary CostFormation language. CostFormation is a YAML based language that lets you configure the conditional logic required to represent your business context. This conditional logic might range from a simple set of mappings to very complex nested logic including multiple allocation rules. Your requirements and creativity are the only constraints with CostFormation (keeping in mind that complex nested allocation can affect performance).

One thing that trips up many new users is the spacing requirements of the YAML language. Each child row should be 1 tab-stop in from its parent row. VS Code will help you manage the spacing requirements by including vertical column indicators (see below).

🚧

YAML Spacing

While you do need to know CloudZero’s CostFormation syntax (which will be described below and in future sections), spacing trips up new users more than anything else

The most common syntax for building dimensions is as follows:

  • ID & Name - Every Dimension needs an ID and a Name. The ID (top row) is how you’ll reference this Dimension if you want to use it in further logic and the Name is what will be shown in the CloudZero Platform.
  • Child - You can leverage the Child Dimension configuration to define an information hierarchy within the CloudZero Explorer. When someone interacts with your Dimension elements in the Explorer, the next dimension they’ll be taken to is whatever you have configured with Child. If Child isn’t defined, then the user will be taken to Resource
  • DefaultValue - Since Dimensions are essentially a set of conditional logic, the DefaultValue represents the ELSE condition. It’s what every resource will be named that doesn’t meet your dimension logic criteria.
  • Rules - Every Dimension will have 1 or more rules. This is the conditional logic that will define your various elements. Pay special attention to the fact that the two rules in the example above both start on the same column (aka tab stop). The next section will explore the most common rule types.

Within the "Rules" section you will define a set of conditional logic blocks which create your dimensions elements. In the example above there are 2 rules. You should think of this logic as if you were creating a SQL CASE statement or an IF-THEN-ELSE. The logic will be processed sequentially and any given resource will only be given a single element value (the first one to match for that resource).

If we consider “My Element 1” from the example above:

This logic equivalency for this CostFormation block is below.

IF (Account = "123456789012" OR Service = "AmazonEC2") THEN Sample Dimension = "My Element 1"

📘

Implicit OR Conditional

One very important point about CostFormation syntax is that within any Conditions, there is an implied OR logic condition between array/list elements

It is possible to override the implicit OR if that’s what your logic requires. You can specify “And:” before the conditions:

This logic equivalency for this CostFormation block is below. Notice how the sources are indented after the AND.

IF (Account = "123456789012" AND Service = "AmazonEC2") THEN Sample Dimension = "My Element 1"

You can also leverage the NOT logic condition if your requirements call for it:

This logic equivalency for this CostFormation block is below. Pay special attention to how the lines are indented in this example.

IF (Account = "123456789012" AND NOT Service = "AmazonEC2") THEN Sample Dimension = "My Element 1"

Micro-Learning


-- Duration: 2 Minutes

-- Topics Covered:
       -- Dimension Structure
       -- Sample Dimension
       -- YAML Spacing