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

Inherits:
Base
  • Object
show all
Defined in:
lib/ufo/stack/builder/resources/security_group/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
10
11
12
# File 'lib/ufo/stack/builder/resources/security_group/elb.rb', line 3

def build
  return unless managed_security_groups?
  return unless @elb_type == "application"

  {
    Type: "AWS::EC2::SecurityGroup",
    Condition: "CreateElbIsTrue",
    Properties: properties
  }
end

#propertiesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ufo/stack/builder/resources/security_group/elb.rb', line 14

def properties
  port = cfn.dig(:Listener, :Port) || cfn.dig(:listener, :port) # backwards compatiblity

  props = {
    GroupDescription: "Allow http to client host",
    VpcId: {Ref: "Vpc"},
    SecurityGroupIngress: [
      {
        IpProtocol: "tcp",
        FromPort: port,
        ToPort: port,
        CidrIp: "0.0.0.0/0"
      }
    ],
    SecurityGroupEgress: [
      {
        IpProtocol: "tcp",
        FromPort: "0",
        ToPort: "65535",
        CidrIp: "0.0.0.0/0"
      }
    ],
    Tags: [
      {
        Key: "Name",
        Value: "#{@stack_name}-elb"
      }
    ]
  }

  if @create_listener_ssl
    ssl_port = cfn.dig(:ListenerSsl, :Port) || cfn.dig(:listener_ssl, :port) # backwards compatiblity
    props[:SecurityGroupIngress] << {
      IpProtocol: "tcp",
      FromPort: ssl_port,
      ToPort: ssl_port,
      CidrIp: "0.0.0.0/0"
    }
  end

  props
end