Module: SparkleFormation::SparkleAttribute::Aws

Included in:
SparkleFormation::SparkleStruct::Aws
Defined in:
lib/sparkle_formation/sparkle_attribute/aws.rb

Overview

AWS specific helper implementations

Instance Method Summary collapse

Instance Method Details

#_account_idHash Also known as: account_id!

Account ID generator

Returns:

  • (Hash)


309
310
311
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 309

def 
  _ref("AWS::AccountId")
end

#_and(*args) ⇒ Hash Also known as: and!

Note:

symbols will be processed and set as condition. strings will be set as condition directly. procs will be evaluated

Fn::And generator

Parameters:

  • args (Object)

    items to be AND’ed together

Returns:

  • (Hash)


216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 216

def _and(*args)
  {
    "Fn::And" => _array(
      *args.map { |v|
      if v.is_a?(Symbol) || v.is_a?(String)
        _condition(v)
      else
        v
      end
    }
    ),
  }
end

#_cf_attr(logical_id, attribute_name) ⇒ Hash Also known as: _cf_get_att, get_att!, attr!

Fn::GetAtt generator

Parameters:

  • logical_id (String, Symbol)

    logical resource name

  • attribute_name (String, Symbol)

    name of desired resource attribute

Returns:

  • (Hash)


115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 115

def _cf_attr(*args)
  r_name = args.first
  args = args.slice(1, args.size)
  __t_stringish(r_name)
  args = args.map do |thing|
    if thing.is_a?(Symbol)
      _process_key(thing, :force)
    else
      thing
    end
  end
  {"Fn::GetAtt" => [__attribute_key(r_name), *args]}
end

#_cf_base64(arg) ⇒ Hash Also known as: base64!

Fn::Base64 generator

Parameters:

  • arg (Object)

    argument to be encoded

Returns:

  • (Hash)


137
138
139
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 137

def _cf_base64(arg)
  {"Fn::Base64" => arg}
end

#_cf_get_azs(region = nil) ⇒ Hash Also known as: get_azs!, azs!

Fn::GetAZs generator

Parameters:

  • region (String, Symbol) (defaults to: nil)

    String will pass through. Symbol will be converted to ref

Returns:

  • (Hash)


147
148
149
150
151
152
153
154
155
156
157
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 147

def _cf_get_azs(region = nil)
  region = case region
           when Symbol
             _cf_ref(region)
           when NilClass
             ""
           else
             region
           end
  {"Fn::GetAZs" => region}
end

#_cf_join(*args, opts = {}) ⇒ Hash Also known as: join!

Fn::Join generator

Parameters:

  • args (String, Hash)

    list of items to join

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :options (Hash)

    options for join function

Returns:

  • (Hash)


18
19
20
21
22
23
24
25
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 18

def _cf_join(*args)
  options = args.detect { |i| i.is_a?(Hash) && i[:options] } || {:options => {}}
  args.delete(options)
  unless args.size == 1
    args = [args]
  end
  {"Fn::Join" => [options[:options][:delimiter] || "", *args]}
end

#_cf_map(map_name, top_level_key, second_level_key) ⇒ Hash Also known as: _cf_find_in_map, find_in_map!, map!

Fn::FindInMap generator

Parameters:

  • map_name (String, Symbol)

    name of map

  • top_level_key (String, Symbol, Hash)

    top level key name

  • second_level_key (String, Symbol, Hash)

    second level key name

Returns:

  • (Hash)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 90

def _cf_map(thing, key, *suffix)
  __t_stringish(thing)
  suffix = suffix.map do |item|
    if item.is_a?(Symbol)
      _process_key(item, :force)
    else
      item
    end
  end
  thing = __attribute_key(thing)
  if key.is_a?(Symbol)
    key = ref!(key)
  end
  {"Fn::FindInMap" => [thing, key, *suffix]}
end

#_cf_ref(thing) ⇒ Hash Also known as: _ref, ref!

Note:

Symbol value will force key processing

Ref generator

Parameters:

  • thing (String, Symbol)

    reference name

Returns:

  • (Hash)


64
65
66
67
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 64

def _cf_ref(thing)
  __t_stringish(thing)
  {"Ref" => __attribute_key(thing)}
end

#_cf_select(index, item) ⇒ Hash Also known as: select!

Fn::Select generator

Parameters:

  • index (String, Symbol, Integer)

    Symbol will be converted to ref

  • item (Object, Symbol)

    Symbol will be converted to ref

Returns:

  • (Hash)


167
168
169
170
171
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 167

def _cf_select(index, item)
  index = index.is_a?(Symbol) ? _cf_ref(index) : index
  item = _cf_ref(item) if item.is_a?(Symbol)
  {"Fn::Select" => [index, item]}
end

#_cf_split(string, delimiter) ⇒ Hash Also known as: split!

Split generator

Parameters:

  • string (String, Hash)

    string to split

  • delimiter (String)

    delimiter to split string

Returns:

  • (Hash)


34
35
36
37
38
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 34

def _cf_split(string, delimiter)
  __t_stringish(string) unless string.is_a?(Hash)
  __t_stringish(delimiter) unless delimiter.is_a?(Hash)
  {"Fn::Split" => [delimiter, string]}
end

#_cf_sub(string, variables = nil) ⇒ Hash Also known as: _sub, sub!

Sub generator

Parameters:

  • string (String, Hash)

    string to apply substitution

  • variables (Hash) (defaults to: nil)

    key value mappings for substitution

Returns:

  • (Hash)


47
48
49
50
51
52
53
54
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 47

def _cf_sub(string, variables = nil)
  if variables.nil?
    {"Fn::Sub" => string}
  else
    __t_hashish(variables)
    {"Fn::Sub" => [string, variables]}
  end
end

#_cf_value_import(thing) ⇒ Hash Also known as: _import_value, import_value!

ValueImport generator

Parameters:

  • thing (String, Symbol, Hash)

    value import

Returns:

  • (Hash)


76
77
78
79
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 76

def _cf_value_import(thing)
  __t_stringish(thing) unless thing.is_a?(Hash)
  {"Fn::ImportValue" => __attribute_key(thing)}
end

#_condition(name) ⇒ Hash Also known as: condition!

Condition generator

Parameters:

  • name (String, Symbol)

    symbol will be processed

Returns:

  • (Hash)


179
180
181
182
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 179

def _condition(name)
  __t_stringish(name)
  {"Condition" => __attribute_key(name)}
end

#_depends_on(resource_name) ⇒ Array<String> #_depends_on(resource_names) ⇒ Array<String> #_depends_on(*resource_names) ⇒ Array<String> Also known as: depends_on!

Note:

this will directly modify the struct at its current context to inject depends on structure

Resource dependency generator

Overloads:

  • #_depends_on(resource_name) ⇒ Array<String>

    Parameters:

    • resource_name (String, Symbol)

      logical resource name

  • #_depends_on(resource_names) ⇒ Array<String>

    Parameters:

    • resource_names (Array<String, Symbol>)

      list of logical resource names

  • #_depends_on(*resource_names) ⇒ Array<String>

    Parameters:

    • resource_names (Array<String, Symbol>)

      list of logical resource names

Returns:

  • (Array<String>)


342
343
344
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 342

def _depends_on(*args)
  _set("DependsOn", [args].flatten.compact.map { |s| __attribute_key(s) })
end

#_equals(v1, v2) ⇒ Hash Also known as: equals!

Fn::Equals generator

Parameters:

  • v1 (Object)
  • v2 (Object)

Returns:

  • (Hash)


237
238
239
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 237

def _equals(v1, v2)
  {"Fn::Equals" => _array(v1, v2)}
end

#_if(cond, true_value, false_value) ⇒ Hash Also known as: if!

Fn::If generator

Parameters:

  • cond (String, Symbol)

    symbol will be case processed

  • true_value (Object)

    item to be used when true

  • false_value (Object)

    item to be used when false

Returns:

  • (Hash)


204
205
206
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 204

def _if(cond, true_value, false_value)
  {"Fn::If" => _array(__attribute_key(cond), true_value, false_value)}
end

#_no_valueHash Also known as: no_value!

No value generator

Returns:

  • (Hash)


282
283
284
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 282

def _no_value
  _ref("AWS::NoValue")
end

#_not(arg) ⇒ Hash Also known as: not!

Fn::Not generator

Parameters:

  • arg (Object)

Returns:

  • (Hash)


247
248
249
250
251
252
253
254
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 247

def _not(arg)
  if arg.is_a?(String) || arg.is_a?(Symbol)
    arg = _condition(arg)
  else
    arg = _array(arg).first
  end
  {"Fn::Not" => [arg]}
end

#_notification_arnsHash Also known as: notification_arns!

Notification ARNs generator

Returns:

  • (Hash)


300
301
302
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 300

def _notification_arns
  _ref("AWS::NotificationARNs")
end

#_on_condition(name) ⇒ SparkleStruct Also known as: on_condition!

Note:

this is used to set a => “Name” into the current context, generally the top level of a resource

Condition setter

Parameters:

  • name (String, Symbol)

    condition name

Returns:



192
193
194
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 192

def _on_condition(name)
  _set(*_condition(name).to_a.flatten)
end

#_or(*args) ⇒ Hash Also known as: or!

Fn::Or generator

Parameters:

  • v1 (Object)
  • v2 (Object)

Returns:

  • (Hash)


263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 263

def _or(*args)
  {
    "Fn::Or" => _array(
      *args.map { |v|
      if v.is_a?(Symbol) || v.is_a?(String)
        _condition(v)
      else
        v
      end
    }
    ),
  }
end

#_regionHash Also known as: region!

Region generator

Returns:

  • (Hash)


291
292
293
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 291

def _region
  _ref("AWS::Region")
end

#_stack_idHash Also known as: stack_id!

Stack ID generator

Returns:

  • (Hash)


318
319
320
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 318

def _stack_id
  _ref("AWS::StackId")
end

#_stack_nameHash Also known as: stack_name!

Stack name generator

Returns:

  • (Hash)


327
328
329
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 327

def _stack_name
  _ref("AWS::StackName")
end

#_stack_output(stack_name, output_name) ⇒ Object Also known as: stack_output!

Reference output value from nested stack

Parameters:

  • stack_name (String, Symbol)

    logical resource name of stack



352
353
354
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 352

def _stack_output(stack_name, output_name)
  _cf_attr(_process_key(stack_name), "Outputs.#{__attribute_key(output_name)}")
end

#_tags(hash) ⇒ SparkleStruct Also known as: tags!

Set tags on a resource

Parameters:

  • hash (Hash)

    Key/value pair tags

Returns:



374
375
376
377
378
379
380
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 374

def _tags(hash)
  __t_hashish(hash)
  _set("Tags",
       hash.map { |k, v|
    {"Key" => __attribute_key(k), "Value" => v}
  })
end

#taggable?TrueClass, FalseClass

Returns resource can be tagged.

Returns:

  • (TrueClass, FalseClass)

    resource can be tagged



359
360
361
362
363
364
365
366
367
368
# File 'lib/sparkle_formation/sparkle_attribute/aws.rb', line 359

def taggable?
  if self[:type]
    resource = _self._provider._resources.lookup(self[:type].gsub("::", "_").downcase)
    resource && resource[:properties].include?("Tags")
  else
    if _parent
      _parent.taggable?
    end
  end
end