Module: CfnDsl::Functions

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

Instance Method Summary collapse

Instance Method Details

#FnAnd(array) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/cfndsl/JSONable.rb', line 45

def FnAnd(array)
  ##
  # Equivalent to the CloudFormation template built in function Fn::And
  if !array || array.count < 2 || array.count > 10
    raise 'The array passed to Fn::And must have at least 2 elements and no more than 10'
  end
  Fn.new("And", array)
end

#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

#FnEquals(value1, value2) ⇒ Object



54
55
56
57
58
# File 'lib/cfndsl/JSONable.rb', line 54

def FnEquals(value1, value2)
  ##
  # Equivalent to the Cloudformation template built in function Fn::Equals
  Fn.new("Equals", [value1, value2])
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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/cfndsl/JSONable.rb', line 87

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

#FnIf(conditionName, trueValue, falseValue) ⇒ Object



60
61
62
63
64
# File 'lib/cfndsl/JSONable.rb', line 60

def FnIf(conditionName, trueValue, falseValue)
  ##
  # Equivalent to the Cloudformation template built in function Fn::If
  Fn.new("If", [conditionName, trueValue, falseValue])
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

#FnNot(value) ⇒ Object



66
67
68
69
70
# File 'lib/cfndsl/JSONable.rb', line 66

def FnNot(value)
  ##
  # Equivalent to the Cloudformation template built in function Fn::Not
  Fn.new("Not", value)
end

#FnOr(array) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/cfndsl/JSONable.rb', line 72

def FnOr(array)
  ##
  # Equivalent to the CloudFormation template built in function Fn::Or
  if !array || array.count < 2 || array.count > 10
    raise 'The array passed to Fn::Or must have at least 2 elements and no more than 10'
  end
  Fn.new("Or", array)
end

#FnSelect(index, array) ⇒ Object



81
82
83
84
85
# File 'lib/cfndsl/JSONable.rb', line 81

def FnSelect(index, array)
  ##
  # Equivalent to the CloudFormation template built in function Fn::Select
  Fn.new("Select", [ index, 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