Module: Cumuliform::DSL::Functions::ConditionFunctions

Included in:
IntrinsicFunctions
Defined in:
lib/cumuliform/dsl/functions.rb

Overview

implements the intrinsic conditions functions

Instance Method Summary collapse

Instance Method Details

#and(condition_1, ..., condition_n) ⇒ Hash

Wraps Fn::And

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#d0e86066

Behaves as a logical AND operator for CloudFormation conditions. Arguments should be other conditions or things that will evaluate to true or false.

Parameters:

  • condition_1 (Hash<boolean-returning ref, intrinsic function, or condition>)

    Condition / value to be ANDed

  • condition_n (Hash<boolean-returning ref, intrinsic function, or condition>)

    Condition / value to be ANDed (min 2, max 10 condition args)

Returns:

  • (Hash)

    the Fn::And object



25
26
27
28
29
30
# File 'lib/cumuliform/dsl/functions.rb', line 25

def and(*conditions)
  unless (2..10).cover?(conditions.length)
    raise ArgumentError, "You must specify AT LEAST 2 and AT MOST 10 conditions"
  end
  {"Fn::And" => conditions}
end

#equals(value, other_value) ⇒ Hash

Wraps Fn::Equals

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#d0e86148

The arguments should be the literal values or refs you want to compare. Returns true or false when CloudFormation evaluates the template.

Parameters:

  • value (String, Hash<value-returning ref>)
  • other_value (String, Hash<value-returning ref>)

Returns:

  • (Hash)

    the Fn::Equals object



82
83
84
# File 'lib/cumuliform/dsl/functions.rb', line 82

def equals(value, other_value)
  {"Fn::Equals" => [value, other_value]}
end

#if(condition, true_value, false_value) ⇒ Hash

Wraps Fn::If

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#d0e86223

CloudFormation evaluates the Condition referred to the logical ID in the condition arg and returns the true_value if true and false_value otherwise. condition cannot be an Fn::Ref, but you can use our xref() helper to ensure the logical ID is valid.

Parameters:

  • condition (String)

    the Logical ID of the Condition to be checked

  • true_value

    the value to be returned if condition evaluates true

  • false_value

    the value to be returned if condition evaluates false

Returns:

  • (Hash)

    the Fn::If object



103
104
105
# File 'lib/cumuliform/dsl/functions.rb', line 103

def if(condition, true_value, false_value)
  {"Fn::If" => [condition, true_value, false_value]}
end

#not(condition) ⇒ Hash

Wraps Fn::Not

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#d0e86402

Behaves as a logical NOT operator for CloudFormation conditions. The argument should be another condition or something that will evaluate to true or false

Parameters:

  • condition (Hash<boolean-returning ref, intrinsic function, or condition>)

    Condition / value to be NOTed

Returns:

  • (Hash)

    the Fn::Not object



67
68
69
# File 'lib/cumuliform/dsl/functions.rb', line 67

def not(condition)
  {"Fn::Not" => [condition]}
end

#or(condition_1, ..., condition_n) ⇒ Hash

Wraps Fn::Or

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#d0e86490

Behaves as a logical OR operator for CloudFormation conditions. Arguments should be other conditions or things that will evaluate to true or false.

Parameters:

  • condition_1 (Hash<boolean-returning ref, intrinsic function, or condition>)

    Condition / value to be ORed

  • condition_n (Hash<boolean-returning ref, intrinsic function, or condition>)

    Condition / value to be ORed (min 2, max 10 condition args)

Returns:

  • (Hash)

    the Fn::Or object



48
49
50
51
52
53
# File 'lib/cumuliform/dsl/functions.rb', line 48

def or(*conditions)
  unless (2..10).cover?(conditions.length)
    raise ArgumentError, "You must specify AT LEAST 2 and AT MOST 10 conditions"
  end
  {"Fn::Or" => conditions}
end