Class: Ufo::Cfn::Stack::Builder::Resources::Listener

Inherits:
Base show all
Defined in:
lib/ufo/cfn/stack/builder/resources/listener.rb

Direct Known Subclasses

ListenerSsl

Instance Attribute Summary

Attributes inherited from Base

#vars

Attributes inherited from Ufo::CLI::Base

#task_definition

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from Ufo::Concerns

#deploy, #info, #ps

Methods included from Ufo::Concerns::Names

#names

Methods included from AwsServices

#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client

Methods included from AwsServices::Concerns

#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns

Methods inherited from Ufo::CLI::Base

#initialize

Methods included from Utils::Sure

#sure?

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Methods included from Utils::Logging

#logger

Constructor Details

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

Instance Method Details

#buildObject



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

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

#default_actionObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ufo/cfn/stack/builder/resources/listener.rb', line 52

def default_action
  {
    Type: "forward",
    TargetGroupArn: {
      "Fn::If": [
        "ElbTargetGroupIsBlank",
        {Ref: "TargetGroup"},
        {Ref: "ElbTargetGroup"}
      ]
    }
  }
end

#default_actionsObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ufo/cfn/stack/builder/resources/listener.rb', line 28

def default_actions
  elb = Ufo.config.elb
  default_actions = elb.default_actions # allow use to override for full control like redirection support
  return default_actions if default_actions

  redirect = elb.redirect
  if redirect.enabled
    [redirect_action(redirect)]
  else
    [default_action]
  end
end

#portObject



24
25
26
# File 'lib/ufo/cfn/stack/builder/resources/listener.rb', line 24

def port
  80
end

#propertiesObject



11
12
13
14
15
16
17
18
# File 'lib/ufo/cfn/stack/builder/resources/listener.rb', line 11

def properties
  {
    DefaultActions: default_actions,
    LoadBalancerArn: {Ref: "Elb"},
    Port: port,
    Protocol: protocol,
  }
end

#protocolObject



20
21
22
# File 'lib/ufo/cfn/stack/builder/resources/listener.rb', line 20

def protocol
  vars[:default_listener_protocol]
end

#redirect_action(redirect) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/ufo/cfn/stack/builder/resources/listener.rb', line 41

def redirect_action(redirect)
  {
    Type: "redirect",
    RedirectConfig: {
      Protocol: redirect.protocol,
      StatusCode: "HTTP_#{redirect.code}", # HTTP_301 and HTTP_302 are valid
      Port: redirect.port,
    }
  }
end