Module: CfnDsl::Functions

Included in:
JSONable, JSONable
Defined in:
lib/cfndsl/JSONable.rb

Instance Method Summary collapse

Instance Method Details

#FnBase64(value) ⇒ Object



15
16
17
18
19
# File 'lib/cfndsl/JSONable.rb', line 15

def FnBase64( value )
  ##
  # Equivalent to the CloudFormation template built in function Fn::Base64
  Fn.new("Base64", value);
end

#FnFindInMap(map, key, value) ⇒ Object



21
22
23
24
25
# File 'lib/cfndsl/JSONable.rb', line 21

def FnFindInMap( map, key, value)
  ##
  # Equivalent to the CloudFormation template built in function Fn::FindInMap
  Fn.new("FindInMap", [map,key,value] )
end

#FnFormat(string, *arguments) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cfndsl/JSONable.rb', line 45

def FnFormat(string, *arguments)
  ##
  # Usage
  #  FnFormat( "This is a %0. It is 100%% %1","test", "effective")
  # or
  #  FnFormat( "This is a %{test}. It is 100%% %{effective}, 
  #            :test=>"test", 
  #            :effective=>"effective")
  #
  # These will each generate a call to Fn::Join that when
  # evaluated will produce the string "This is a test. It is 100%
  # effective."
  #
  # Think of this as %0,%1, etc in the format string being replaced by the 
  # corresponding arguments given after the format string. '%%' is replaced
  # by the '%' character. 
  # 
  # The actual Fn::Join call corresponding to the above FnFormat call would be
  # {"Fn::Join": ["",["This is a ","test",". It is 100","%"," ","effective"]]}
  #
  # If no arguments are given, or if a hash is given and the format
  # variable name does not exist in the hash, it is used as a Ref 
  # to an existing resource or parameter.
  #
  array = [];
  if(arguments.length == 0 ||
     (arguments.length == 1 && arguments[0].instance_of?(Hash)) ) then
    hash = arguments[0] || {}
    string.scan( /(.*?)(%(%|\{([\w:]+)\})|\z)/m ) do |x,y|
      array.push $1 if $1 && $1 != ""
      if( $3 == '%' ) then
        array.push '%'
      elsif( $3 ) then
        array.push hash[ $4 ] || hash[ $4.to_sym ] || Ref( $4 )
      end
    end  
  else
    string.scan( /(.*?)(%(%|\d+)|\z)/m ) do |x,y|
      array.push $1 if $1 && $1 != ""
      if( $3 == '%' ) then
        array.push '%'
      elsif( $3 ) then
        array.push arguments[ $3.to_i ]
      end
    end  
  end
  Fn.new("Join", ["", array])
end

#FnGetAtt(logicalResource, attribute) ⇒ Object



27
28
29
30
31
# File 'lib/cfndsl/JSONable.rb', line 27

def FnGetAtt(logicalResource, attribute)
  ##
  # Equivalent to the CloudFormation template built in function Fn::GetAtt
  Fn.new( "GetAtt", [logicalResource, attribute], [logicalResource] )
end

#FnGetAZs(region) ⇒ Object



33
34
35
36
37
# File 'lib/cfndsl/JSONable.rb', line 33

def FnGetAZs(region)
  ##
  # Equivalent to the CloudFormation template built in function Fn::GetAZs
  Fn.new("GetAZs", region)
end

#FnJoin(string, array) ⇒ Object



39
40
41
42
43
# File 'lib/cfndsl/JSONable.rb', line 39

def FnJoin(string, array)
  ##
  # Equivalent to the CloudFormation template built in function Fn::Join
  Fn.new("Join", [ string, array] )
end

#Ref(value) ⇒ Object

These functions are available anywhere inside a block for a JSONable object.



9
10
11
12
13
# File 'lib/cfndsl/JSONable.rb', line 9

def Ref(value) 
  ##
  # Equivalent to the CloudFormation template built in function Ref
  RefDefinition.new(value)
end