Class: Cumuliform::DSL::Functions::IntrinsicFunctions
- Inherits:
-
Object
- Object
- Cumuliform::DSL::Functions::IntrinsicFunctions
- Includes:
- ConditionFunctions
- 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
-
#base64(value) ⇒ Hash
Wraps Fn::Base64.
-
#cidr(ip_block, count, cidr_bits) ⇒ Hash
Wraps Fn::Cidr.
-
#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.
-
#import_value(shared_value_to_import) ⇒ Hash
Wraps Fn::ImportValue.
-
#initialize(template) ⇒ IntrinsicFunctions
constructor
private
A new instance of IntrinsicFunctions.
-
#join(separator, args) ⇒ Hash
Wraps Fn::Join.
-
#select(index, array) ⇒ Hash
Wraps Fn::Select.
-
#split(delimiter, source_string) ⇒ Hash
Wraps Fn::Split.
-
#sub(string, substitutions = nil) ⇒ Hash
Wraps Fn::Sub.
-
#transform(macro_name, parameters = {}) ⇒ Hash
Wraps Fn::Transform.
Methods included from ConditionFunctions
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.
116 117 118 |
# File 'lib/cumuliform/dsl/functions.rb', line 116 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.
113 114 115 |
# File 'lib/cumuliform/dsl/functions.rb', line 113 def template @template end |
Instance Method Details
#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
173 174 175 |
# File 'lib/cumuliform/dsl/functions.rb', line 173 def base64(value) {"Fn::Base64" => value} end |
#cidr(ip_block, count, cidr_bits) ⇒ Hash
237 238 239 |
# File 'lib/cumuliform/dsl/functions.rb', line 237 def cidr(ip_block, count, cidr_bits) {"Fn::Cidr" => [ip_block, count, cidr_bits]} end |
#find_in_map(mapping_logical_id, level_1_key, level_2_key) ⇒ Hash
129 130 131 132 |
# File 'lib/cumuliform/dsl/functions.rb', line 129 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
143 144 145 146 |
# File 'lib/cumuliform/dsl/functions.rb', line 143 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.
188 189 190 |
# File 'lib/cumuliform/dsl/functions.rb', line 188 def get_azs(value = "") {"Fn::GetAZs" => value} end |
#import_value(shared_value_to_import) ⇒ Hash
Wraps Fn::ImportValue
see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html
249 250 251 |
# File 'lib/cumuliform/dsl/functions.rb', line 249 def import_value(shared_value_to_import) {"Fn::ImportValue" => shared_value_to_import} end |
#join(separator, args) ⇒ Hash
156 157 158 159 |
# File 'lib/cumuliform/dsl/functions.rb', line 156 def join(separator, args) raise ArgumentError, "Second argument must be an Array" unless args.is_a?(Array) {"Fn::Join" => [separator, args]} 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).
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/cumuliform/dsl/functions.rb', line 209 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 |
#split(delimiter, source_string) ⇒ Hash
261 262 263 |
# File 'lib/cumuliform/dsl/functions.rb', line 261 def split(delimiter, source_string) {"Fn::Split" => [delimiter, source_string]} end |
#sub(string, substitutions = nil) ⇒ Hash
275 276 277 278 279 280 281 282 |
# File 'lib/cumuliform/dsl/functions.rb', line 275 def sub(string, substitutions = nil) if substitutions.nil? args = string else args = [string, substitutions] end {"Fn::Sub" => args} end |
#transform(macro_name, parameters = {}) ⇒ Hash
292 293 294 295 296 297 298 299 |
# File 'lib/cumuliform/dsl/functions.rb', line 292 def transform(macro_name, parameters = {}) { "Fn::Transform" => { "Name" => macro_name, "Parameters" => parameters } } end |