Module: CloudShaped::CoreMethods

Included in:
DSL, Interpolation, SnsMethods
Defined in:
lib/cloud_shaped/core_methods.rb

Instance Method Summary collapse

Instance Method Details

#output(value) ⇒ Object

Returns an Output declaration.

Examples:

output(ref("loadBalancer"))

Parameters:

  • value

    the output value (usually a reference to a resource)



50
51
52
53
54
# File 'lib/cloud_shaped/core_methods.rb', line 50

def output(value)
  {
    "Value" => value
  }
end

#parameter(options = {}) ⇒ Object

Returns a CloudFormation Parameter declaration.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :type (String) — default: "String"

    the parameter type

  • :description (String)

    parameter description

  • :default (String)

    a default value



36
37
38
39
40
41
# File 'lib/cloud_shaped/core_methods.rb', line 36

def parameter(options = {})
  defaults = {
    "Type" => "String"
  }
  defaults.merge(options.camelate_keys)
end

#ref(resource_name, attribute_name = nil) ⇒ Object

Returns a resource reference.

If attribute_name is specified, we use “Fn::GetAtt”; otherwise, we use “Ref”.

Parameters:

  • resource_name (String)

    name of the resource

  • attribute_name (String) (defaults to: nil)

    atttribute of the resource to refer to



90
91
92
93
94
95
96
# File 'lib/cloud_shaped/core_methods.rb', line 90

def ref(resource_name, attribute_name = nil)
  if attribute_name
    { "Fn::GetAtt" => [resource_name, attribute_name] }
  else
    { "Ref" => resource_name }
  end
end

#resource(type, properties = {}, attributes = {}) {|properties, attributes| ... } ⇒ Object

Returns a CloudFormation Resource declaration.

Properties and additional resource attributes can be passed in the call, or defined using an optional block.

Examples:

resource("AWS::ElasticLoadBalancing::LoadBalancer", "Scheme" => "internal") do |elb|
  elb["SecurityGroups"] = [ref("appSecurityGroup")]
end

Parameters:

  • type (String)

    the resource type

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

    resource properties

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

    additional resource attributes

Yields:

  • (properties, attributes)


20
21
22
23
24
25
26
27
28
# File 'lib/cloud_shaped/core_methods.rb', line 20

def resource(type, properties = {}, attributes = {})
  properties = properties.camelate_keys
  yield properties, attributes if block_given?
  properties.select! { |k,v| v != nil }
  attributes.merge(
    "Type" => type,
    "Properties" => properties
  )
end

#tag(key, value, extra_properties = {}) ⇒ Hash

Returns a Tag.

Examples:

tag("name", "bob") #=> { "Key" => "name", "Value" => "bob "}

Parameters:

  • key (String)

    tag name

  • value

    tag value

Returns:

  • (Hash)

    a Tag structure



65
66
67
68
69
70
# File 'lib/cloud_shaped/core_methods.rb', line 65

def tag(key, value, extra_properties = {})
  {
    "Key" => key,
    "Value" => value
  }.merge(extra_properties)
end

#tags(tag_map, extra_properties = {}) ⇒ Object

Returns a list of Tags.

Examples:

tags("application" => "atlas", "version" => "1.2.3")

Parameters:

  • tag_map (Hash)

    mapping of Tag keys to values



79
80
81
# File 'lib/cloud_shaped/core_methods.rb', line 79

def tags(tag_map, extra_properties = {})
  tag_map.map { |k,v| tag(k,v, extra_properties) }
end