Class: Ufo::Stack::Builder::Resources::Elb

Inherits:
Base
  • Object
show all
Defined in:
lib/ufo/stack/builder/resources/elb.rb

Instance Method Summary collapse

Methods inherited from Base

build, #copy_instance_variables, #initialize, #managed_security_group, #managed_security_groups?, #security_groups

Methods included from Ufo::Settings

#cfn, #network, #settings

Constructor Details

This class inherits a constructor from Ufo::Stack::Builder::Base

Instance Method Details

#buildObject



3
4
5
6
7
8
9
# File 'lib/ufo/stack/builder/resources/elb.rb', line 3

def build
  {
    Type: "AWS::ElasticLoadBalancingV2::LoadBalancer",
    Condition: "CreateElbIsTrue",
    Properties: properties,
  }
end

#propertiesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ufo/stack/builder/resources/elb.rb', line 11

def properties
  props = {
    Type: @elb_type,
    Tags: [
      {Key: "Name", Value: @stack_name}
    ],
    Subnets: {Ref: "ElbSubnets"},
    Scheme: "internet-facing"
  }

  props[:SecurityGroups] = security_groups(:elb) if @elb_type == "application"
  subnets(props)

  props
end

#subnet_mappingsObject



36
37
38
39
40
41
42
43
# File 'lib/ufo/stack/builder/resources/elb.rb', line 36

def subnet_mappings
  @subnet_mappings.map do |allocation_id, subnet_id|
    {
      AllocationId: allocation_id,
      SubnetId: subnet_id,
    }
  end
end

#subnets(props) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/ufo/stack/builder/resources/elb.rb', line 27

def subnets(props)
  mappings = @elb_type == "network" && @subnet_mappings && !@subnet_mappings.empty?
  if mappings
    props[:SubnetMappings] = subnet_mappings
  else
    props[:Subnets] = {Ref: "ElbSubnets"}
  end
end