Module: CfnDsl::Functions
Overview
These functions are available anywhere inside a block for a JSONable object.
Instance Method Summary collapse
-
#FnAnd(array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::And.
-
#FnBase64(value) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Base64.
-
#FnCidr(ipblock, count, sizemask) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Cidr.
-
#FnEquals(value1, value2) ⇒ Object
Equivalent to the Cloudformation template built in function Fn::Equals.
-
#FnFindInMap(map, key, value) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::FindInMap.
-
#FnFormat(string, *arguments) ⇒ Object
DEPRECATED 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’).
-
#FnGetAtt(logical_resource, attribute) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::GetAtt.
-
#FnGetAZs(region) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::GetAZs.
-
#FnIf(condition_name, true_value, false_value) ⇒ Object
Equivalent to the Cloudformation template built in function Fn::If.
-
#FnImportValue(value) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::ImportValue.
-
#FnJoin(string, array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Join.
-
#FnNot(value) ⇒ Object
Equivalent to the Cloudformation template built in function Fn::Not.
-
#FnOr(array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Or.
-
#FnSelect(index, array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Select.
-
#FnSplit(string, array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Split.
-
#FnSub(string, substitutions = nil) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Sub.
-
#Ref(value) ⇒ Object
Equivalent to the CloudFormation template built in function Ref.
Instance Method Details
#FnAnd(array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::And
45 46 47 48 |
# File 'lib/cfndsl/jsonable.rb', line 45 def FnAnd(array) raise 'The array passed to Fn::And must have at least 2 elements and no more than 10' if !array || array.count < 2 || array.count > 10 Fn.new('And', array) end |
#FnBase64(value) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Base64
15 16 17 |
# File 'lib/cfndsl/jsonable.rb', line 15 def FnBase64(value) Fn.new('Base64', value) end |
#FnCidr(ipblock, count, sizemask) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Cidr
146 147 148 |
# File 'lib/cfndsl/jsonable.rb', line 146 def FnCidr(ipblock, count, sizemask) Fn.new('Cidr', [ipblock, count, sizemask]) end |
#FnEquals(value1, value2) ⇒ Object
Equivalent to the Cloudformation template built in function Fn::Equals
51 52 53 |
# File 'lib/cfndsl/jsonable.rb', line 51 def FnEquals(value1, value2) Fn.new('Equals', [value1, value2]) end |
#FnFindInMap(map, key, value) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::FindInMap
20 21 22 |
# File 'lib/cfndsl/jsonable.rb', line 20 def FnFindInMap(map, key, value) Fn.new('FindInMap', [map, key, value]) end |
#FnFormat(string, *arguments) ⇒ Object
DEPRECATED 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 [“”,[“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.
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cfndsl/jsonable.rb', line 120 def FnFormat(string, *arguments) warn '`FnFormat` is deprecated and will be removed a future release. Use `FnSub` instead' array = [] if arguments.empty? || (arguments.length == 1 && arguments[0].instance_of?(Hash)) hash = arguments[0] || {} string.scan(/(.*?)(?:%(%|\{([\w:]+)\})|\z)/m) do |x, y, z| array.push x if x && !x.empty? next unless y array.push(y == '%' ? '%' : (hash[z] || hash[z.to_sym] || Ref(z))) end else string.scan(/(.*?)(?:%(%|\d+)|\z)/m) do |x, y| array.push x if x && !x.empty? next unless y array.push(y == '%' ? '%' : arguments[y.to_i]) end end Fn.new('Join', ['', array]) end |
#FnGetAtt(logical_resource, attribute) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::GetAtt
25 26 27 |
# File 'lib/cfndsl/jsonable.rb', line 25 def FnGetAtt(logical_resource, attribute) Fn.new('GetAtt', [logical_resource, attribute]) end |
#FnGetAZs(region) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::GetAZs
30 31 32 |
# File 'lib/cfndsl/jsonable.rb', line 30 def FnGetAZs(region) Fn.new('GetAZs', region) end |
#FnIf(condition_name, true_value, false_value) ⇒ Object
Equivalent to the Cloudformation template built in function Fn::If
56 57 58 |
# File 'lib/cfndsl/jsonable.rb', line 56 def FnIf(condition_name, true_value, false_value) Fn.new('If', [condition_name, true_value, false_value]) end |
#FnImportValue(value) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::ImportValue
92 93 94 |
# File 'lib/cfndsl/jsonable.rb', line 92 def FnImportValue(value) Fn.new('ImportValue', value) end |
#FnJoin(string, array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Join
35 36 37 |
# File 'lib/cfndsl/jsonable.rb', line 35 def FnJoin(string, array) Fn.new('Join', [string, array]) end |
#FnNot(value) ⇒ Object
Equivalent to the Cloudformation template built in function Fn::Not
61 62 63 64 65 66 67 |
# File 'lib/cfndsl/jsonable.rb', line 61 def FnNot(value) if value.is_a?(Array) Fn.new('Not', value) else Fn.new('Not', [value]) end end |
#FnOr(array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Or
70 71 72 73 |
# File 'lib/cfndsl/jsonable.rb', line 70 def FnOr(array) raise 'The array passed to Fn::Or must have at least 2 elements and no more than 10' if !array || array.count < 2 || array.count > 10 Fn.new('Or', array) end |
#FnSelect(index, array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Select
76 77 78 |
# File 'lib/cfndsl/jsonable.rb', line 76 def FnSelect(index, array) Fn.new('Select', [index, array]) end |
#FnSplit(string, array) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Split
40 41 42 |
# File 'lib/cfndsl/jsonable.rb', line 40 def FnSplit(string, array) Fn.new('Split', [string, array]) end |
#FnSub(string, substitutions = nil) ⇒ Object
Equivalent to the CloudFormation template built in function Fn::Sub
81 82 83 84 85 86 87 88 89 |
# File 'lib/cfndsl/jsonable.rb', line 81 def FnSub(string, substitutions = nil) raise ArgumentError, 'The first argument passed to Fn::Sub must be a string' unless string.is_a? String if substitutions raise ArgumentError, 'The second argument passed to Fn::Sub must be a Hash' unless substitutions.is_a? Hash Fn.new('Sub', [string, substitutions]) else Fn.new('Sub', string) end end |
#Ref(value) ⇒ Object
Equivalent to the CloudFormation template built in function Ref
10 11 12 |
# File 'lib/cfndsl/jsonable.rb', line 10 def Ref(value) RefDefinition.new(value) end |