Sha256: da10d539791c9161d9ec94f6aabf5367424113d2f72db5380de448cc5ff77c27

Contents?: true

Size: 1.35 KB

Versions: 24

Compression:

Stored size: 1.35 KB

Contents

class Ufo::Cfn::Stack::Builder::Resources
  class Listener < Base
    def build
      {
        Type: "AWS::ElasticLoadBalancingV2::Listener",
        Condition: "CreateElbIsTrue",
        Properties: properties,
      }
    end

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

    def protocol
      vars[:default_listener_protocol]
    end

    def port
      80
    end

    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

    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

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

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ufo-6.3.1 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.3.0 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.2.5 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.2.4 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.2.3 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.2.2 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.2.1 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.2.0 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.1.5 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.1.4 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.1.3 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.1.2 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.1.1 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.1.0 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.0.9 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.0.8 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.0.7 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.0.6 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.0.5 lib/ufo/cfn/stack/builder/resources/listener.rb
ufo-6.0.4 lib/ufo/cfn/stack/builder/resources/listener.rb