Class: Cumuliform::DSL::Functions::IntrinsicFunctions
- Inherits:
-
Object
- Object
- Cumuliform::DSL::Functions::IntrinsicFunctions
- Defined in:
- lib/cumuliform/dsl/functions.rb
Overview
implements wrappers for the intrinsic functions Fn::*
Instance Attribute Summary collapse
- #template ⇒ Object readonly private
Instance Method Summary collapse
-
#and(condition_1, ..., condition_n) ⇒ Hash
Wraps Fn::And.
-
#base64(value) ⇒ Hash
Wraps Fn::Base64.
-
#equals(value, other_value) ⇒ Hash
Wraps Fn::Equals.
-
#find_in_map(mapping_logical_id, level_1_key, level_2_key) ⇒ Hash
Wraps Fn::FindInMap.
-
#get_att(resource_logical_id, attr_name) ⇒ Hash
Wraps Fn::GetAtt.
-
#get_azs(value = "") ⇒ Hash
Wraps Fn::GetAZs.
-
#if(condition, true_value, false_value) ⇒ Hash
Wraps Fn::If.
-
#initialize(template) ⇒ IntrinsicFunctions
constructor
private
A new instance of IntrinsicFunctions.
-
#join(separator, args) ⇒ Hash
Wraps Fn::Join.
-
#not(condition) ⇒ Hash
Wraps Fn::Not.
-
#or(condition_1, ..., condition_n) ⇒ Hash
Wraps Fn::Or.
-
#select(index, array) ⇒ Hash
Wraps Fn::Select.
Constructor Details
#initialize(template) ⇒ IntrinsicFunctions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of IntrinsicFunctions.
13 14 15 |
# File 'lib/cumuliform/dsl/functions.rb', line 13 def initialize(template) @template = template end |
Instance Attribute Details
#template ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'lib/cumuliform/dsl/functions.rb', line 10 def template @template end |
Instance Method Details
#and(condition_1, ..., condition_n) ⇒ Hash
Wraps Fn::And
Behaves as a logical AND operator for CloudFormation conditions. Arguments should be other conditions or things that will evaluate to true
or false
.
173 174 175 176 177 178 |
# File 'lib/cumuliform/dsl/functions.rb', line 173 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 |
#base64(value) ⇒ Hash
Wraps Fn::Base64
see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-base64.html
The argument should either be a string or an intrinsic function that evaluates to a string when CloudFormation executes the template
see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-base64.html
70 71 72 |
# File 'lib/cumuliform/dsl/functions.rb', line 70 def base64(value) {"Fn::Base64" => value} end |
#equals(value, other_value) ⇒ Hash
Wraps Fn::Equals
The arguments should be the literal values or refs you want to compare. Returns true or false when CloudFormation evaluates the template.
100 101 102 |
# File 'lib/cumuliform/dsl/functions.rb', line 100 def equals(value, other_value) {"Fn::Equals" => [value, other_value]} end |
#find_in_map(mapping_logical_id, level_1_key, level_2_key) ⇒ Hash
26 27 28 29 |
# File 'lib/cumuliform/dsl/functions.rb', line 26 def find_in_map(mapping_logical_id, level_1_key, level_2_key) template.verify_mapping_logical_id!(mapping_logical_id) {"Fn::FindInMap" => [mapping_logical_id, level_1_key, level_2_key]} end |
#get_att(resource_logical_id, attr_name) ⇒ Hash
40 41 42 43 |
# File 'lib/cumuliform/dsl/functions.rb', line 40 def get_att(resource_logical_id, attr_name) template.verify_resource_logical_id!(resource_logical_id) {"Fn::GetAtt" => [resource_logical_id, attr_name]} end |
#get_azs(value = "") ⇒ Hash
Wraps Fn::GetAZs
CloudFormation evaluates this to an array of availability zone names.
85 86 87 |
# File 'lib/cumuliform/dsl/functions.rb', line 85 def get_azs(value = "") {"Fn::GetAZs" => value} end |
#if(condition, true_value, false_value) ⇒ Hash
Wraps Fn::If
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.
121 122 123 |
# File 'lib/cumuliform/dsl/functions.rb', line 121 def if(condition, true_value, false_value) {"Fn::If" => [condition, true_value, false_value]} end |
#join(separator, args) ⇒ Hash
53 54 55 56 |
# File 'lib/cumuliform/dsl/functions.rb', line 53 def join(separator, args) raise ArgumentError, "Second argument must be an Array" unless args.is_a?(Array) {"Fn::Join" => [separator, args]} end |
#not(condition) ⇒ Hash
Wraps Fn::Not
Behaves as a logical NOT operator for CloudFormation conditions. The argument should be another condition or something that will evaluate to true
or false
215 216 217 |
# File 'lib/cumuliform/dsl/functions.rb', line 215 def not(condition) {"Fn::Not" => [condition]} end |
#or(condition_1, ..., condition_n) ⇒ Hash
Wraps Fn::Or
Behaves as a logical OR operator for CloudFormation conditions. Arguments should be other conditions or things that will evaluate to true
or false
.
196 197 198 199 200 201 |
# File 'lib/cumuliform/dsl/functions.rb', line 196 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 |
#select(index, array) ⇒ Hash
Wraps Fn::Select
see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-select.html
CloudFormation evaluates the index
(which can be an integer-as-a-string or a ref
which evaluates to a number) and returns the corresponding item from the array (which can be an array literal, or the result of Fn::GetAZs
, or one of Fn::GetAtt
, Fn::If
, and Ref
(if they would return an Array).
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/cumuliform/dsl/functions.rb', line 142 def select(index, array) ref_style_index = index.is_a?(Hash) && index.has_key?("Fn::Ref") positive_int_style_index = index.is_a?(Integer) && index >= 0 unless ref_style_index || positive_int_style_index raise ArgumentError, "index must be a positive integer or Fn::Ref" end if positive_int_style_index if array.is_a?(Array) && index >= array.length raise IndexError, "index must be in the range 0 <= index < array.length" end index = index.to_s end {"Fn::Select" => [index, array]} end |