class Cumuliform::DSL::Functions::IntrinsicFunctions

implements wrappers for the intrinsic functions Fn::*

Attributes

template[R]

@api private

Public Class Methods

new(template) click to toggle source

@api private

# File lib/cumuliform/dsl/functions.rb, line 116
def initialize(template)
  @template = template
end

Public Instance Methods

base64(value) click to toggle source

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

@param value [String, Hash<string-returning instrinsic function>] The

separator string to join the array  elements with

@return [Hash] the Fn::Base64 object

# File lib/cumuliform/dsl/functions.rb, line 173
def base64(value)
  {"Fn::Base64" => value}
end
cidr(ip_block, count, cidr_bits) click to toggle source

Wraps Fn::Cidr

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-cidr.html

@param ip_block [String] The user-specified CIDR address block to be

split into smaller CIDR blocks. (e.g. "10.0.0.0/16")

@param count [Integer] The number of CIDRs to generate. Valid range is

between 1 and 256

@param cidr_bits [Integer] The number of subnet bits for the CIDR. For

example, specifying a value "8" for this parameter will create a
CIDR with a mask of "/24".

@return [Hash] The Fn::Cidr object

# 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) click to toggle source

Wraps Fn::FindInMap

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html

@param mapping_logical_id [String] The logical ID of the mapping we

want to look up a value from

@param level_1_key [String] Key 1 @param level_2_key [String] Key 2 @return [Hash] the Fn::FindInMap object

# 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) click to toggle source

Wraps Fn::GetAtt

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

@param resource_logical_id [String] The Logical ID of resource we

want to get an attribute of

@param attr_name [String] The name of the attribute to get the value

of

@return [Hash] the Fn::GetAtt object

# 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 = "") click to toggle source

Wraps Fn::GetAZs

CloudFormation evaluates this to an array of availability zone names.

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getavailabilityzones.html

@param value [String, Hash<ref('AWS::Region')>] The AWS region to get

the array of Availability Zones of. Empty string (the default) is
equivalent to specifying `ref('AWS::Region')` which evaluates to
the region the stack is being created in

@return [Hash] the Fn::GetAZs object

# File lib/cumuliform/dsl/functions.rb, line 188
def get_azs(value = "")
  {"Fn::GetAZs" => value}
end
import_value(shared_value_to_import) click to toggle source

Wraps Fn::ImportValue

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html

@param shared_value_to_import [String] The stack output value to

import

@return [Hash] The Fn::ImportValue object

# 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) click to toggle source

Wraps Fn::Join

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html

@param separator [String] The separator string to join the array

elements with

@param args [Array<String>] The array of strings to join @return [Hash] the Fn::Join object

# 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) click to toggle source

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).

@param index [Integer, Hash<value-returning ref>] The index to

retrieve from <tt>array</tt>

@param array [Array, Hash<array-returning ref of intrinsic function>]

The array to retrieve from

@return [Hash] the Fn::Select object

# 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) click to toggle source

Wraps Fn::Split

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-split.html

@param delimiter [String] The delimiter to split the source_string on @param source_string [String] The string to split @return [Hash] The Fn::Split object

# File lib/cumuliform/dsl/functions.rb, line 261
def split(delimiter, source_string)
  {"Fn::Split" => [delimiter, source_string]}
end
sub(string, substitutions = nil) click to toggle source

Wraps Fn::Sub

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html

@param string [String] The string to substitute values into @param substitutions [Hash<String => String,Hash>] Optional hash of

variable names and the value to substitute them for. The value can
also be somethings like an Fn:Ref invocation.

@return [Hash] The Fn::Sub object

# 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 = {}) click to toggle source

Wraps Fn::Transform

see docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-transform.html

@param macro_name [String] The name of the macro to call @param parameters [Hash] The hash of parameter names/values @return [Hash] The Fn::Transform object

# File lib/cumuliform/dsl/functions.rb, line 292
def transform(macro_name, parameters = {})
  {
    "Fn::Transform" => {
      "Name" => macro_name,
      "Parameters" => parameters
    }
  }
end