{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ECS.Types.LoadBalancer
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ECS.Types.LoadBalancer where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The load balancer configuration to use with a service or task set.
--
-- For specific notes and restrictions regarding the use of load balancers
-- with services and task sets, see the CreateService and CreateTaskSet
-- actions.
--
-- /See:/ 'newLoadBalancer' smart constructor.
data LoadBalancer = LoadBalancer'
  { -- | The name of the load balancer to associate with the Amazon ECS service
    -- or task set.
    --
    -- A load balancer name is only specified when using a Classic Load
    -- Balancer. If you are using an Application Load Balancer or a Network
    -- Load Balancer the load balancer name parameter should be omitted.
    LoadBalancer -> Maybe Text
loadBalancerName :: Prelude.Maybe Prelude.Text,
    -- | The name of the container (as it appears in a container definition) to
    -- associate with the load balancer.
    LoadBalancer -> Maybe Text
containerName :: Prelude.Maybe Prelude.Text,
    -- | The full Amazon Resource Name (ARN) of the Elastic Load Balancing target
    -- group or groups associated with a service or task set.
    --
    -- A target group ARN is only specified when using an Application Load
    -- Balancer or Network Load Balancer. If you are using a Classic Load
    -- Balancer the target group ARN should be omitted.
    --
    -- For services using the @ECS@ deployment controller, you can specify one
    -- or multiple target groups. For more information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/register-multiple-targetgroups.html Registering Multiple Target Groups with a Service>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    --
    -- For services using the @CODE_DEPLOY@ deployment controller, you are
    -- required to define two target groups for the load balancer. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-bluegreen.html Blue\/Green Deployment with CodeDeploy>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    --
    -- If your service\'s task definition uses the @awsvpc@ network mode (which
    -- is required for the Fargate launch type), you must choose @ip@ as the
    -- target type, not @instance@, when creating your target groups because
    -- tasks that use the @awsvpc@ network mode are associated with an elastic
    -- network interface, not an Amazon EC2 instance.
    LoadBalancer -> Maybe Text
targetGroupArn :: Prelude.Maybe Prelude.Text,
    -- | The port on the container to associate with the load balancer. This port
    -- must correspond to a @containerPort@ in the task definition the tasks in
    -- the service are using. For tasks that use the EC2 launch type, the
    -- container instance they are launched on must allow ingress traffic on
    -- the @hostPort@ of the port mapping.
    LoadBalancer -> Maybe Int
containerPort :: Prelude.Maybe Prelude.Int
  }
  deriving (LoadBalancer -> LoadBalancer -> Bool
(LoadBalancer -> LoadBalancer -> Bool)
-> (LoadBalancer -> LoadBalancer -> Bool) -> Eq LoadBalancer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LoadBalancer -> LoadBalancer -> Bool
$c/= :: LoadBalancer -> LoadBalancer -> Bool
== :: LoadBalancer -> LoadBalancer -> Bool
$c== :: LoadBalancer -> LoadBalancer -> Bool
Prelude.Eq, ReadPrec [LoadBalancer]
ReadPrec LoadBalancer
Int -> ReadS LoadBalancer
ReadS [LoadBalancer]
(Int -> ReadS LoadBalancer)
-> ReadS [LoadBalancer]
-> ReadPrec LoadBalancer
-> ReadPrec [LoadBalancer]
-> Read LoadBalancer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LoadBalancer]
$creadListPrec :: ReadPrec [LoadBalancer]
readPrec :: ReadPrec LoadBalancer
$creadPrec :: ReadPrec LoadBalancer
readList :: ReadS [LoadBalancer]
$creadList :: ReadS [LoadBalancer]
readsPrec :: Int -> ReadS LoadBalancer
$creadsPrec :: Int -> ReadS LoadBalancer
Prelude.Read, Int -> LoadBalancer -> ShowS
[LoadBalancer] -> ShowS
LoadBalancer -> String
(Int -> LoadBalancer -> ShowS)
-> (LoadBalancer -> String)
-> ([LoadBalancer] -> ShowS)
-> Show LoadBalancer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LoadBalancer] -> ShowS
$cshowList :: [LoadBalancer] -> ShowS
show :: LoadBalancer -> String
$cshow :: LoadBalancer -> String
showsPrec :: Int -> LoadBalancer -> ShowS
$cshowsPrec :: Int -> LoadBalancer -> ShowS
Prelude.Show, (forall x. LoadBalancer -> Rep LoadBalancer x)
-> (forall x. Rep LoadBalancer x -> LoadBalancer)
-> Generic LoadBalancer
forall x. Rep LoadBalancer x -> LoadBalancer
forall x. LoadBalancer -> Rep LoadBalancer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LoadBalancer x -> LoadBalancer
$cfrom :: forall x. LoadBalancer -> Rep LoadBalancer x
Prelude.Generic)

-- |
-- Create a value of 'LoadBalancer' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'loadBalancerName', 'loadBalancer_loadBalancerName' - The name of the load balancer to associate with the Amazon ECS service
-- or task set.
--
-- A load balancer name is only specified when using a Classic Load
-- Balancer. If you are using an Application Load Balancer or a Network
-- Load Balancer the load balancer name parameter should be omitted.
--
-- 'containerName', 'loadBalancer_containerName' - The name of the container (as it appears in a container definition) to
-- associate with the load balancer.
--
-- 'targetGroupArn', 'loadBalancer_targetGroupArn' - The full Amazon Resource Name (ARN) of the Elastic Load Balancing target
-- group or groups associated with a service or task set.
--
-- A target group ARN is only specified when using an Application Load
-- Balancer or Network Load Balancer. If you are using a Classic Load
-- Balancer the target group ARN should be omitted.
--
-- For services using the @ECS@ deployment controller, you can specify one
-- or multiple target groups. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/register-multiple-targetgroups.html Registering Multiple Target Groups with a Service>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- For services using the @CODE_DEPLOY@ deployment controller, you are
-- required to define two target groups for the load balancer. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-bluegreen.html Blue\/Green Deployment with CodeDeploy>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- If your service\'s task definition uses the @awsvpc@ network mode (which
-- is required for the Fargate launch type), you must choose @ip@ as the
-- target type, not @instance@, when creating your target groups because
-- tasks that use the @awsvpc@ network mode are associated with an elastic
-- network interface, not an Amazon EC2 instance.
--
-- 'containerPort', 'loadBalancer_containerPort' - The port on the container to associate with the load balancer. This port
-- must correspond to a @containerPort@ in the task definition the tasks in
-- the service are using. For tasks that use the EC2 launch type, the
-- container instance they are launched on must allow ingress traffic on
-- the @hostPort@ of the port mapping.
newLoadBalancer ::
  LoadBalancer
newLoadBalancer :: LoadBalancer
newLoadBalancer =
  LoadBalancer' :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Int -> LoadBalancer
LoadBalancer'
    { $sel:loadBalancerName:LoadBalancer' :: Maybe Text
loadBalancerName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:containerName:LoadBalancer' :: Maybe Text
containerName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:targetGroupArn:LoadBalancer' :: Maybe Text
targetGroupArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:containerPort:LoadBalancer' :: Maybe Int
containerPort = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the load balancer to associate with the Amazon ECS service
-- or task set.
--
-- A load balancer name is only specified when using a Classic Load
-- Balancer. If you are using an Application Load Balancer or a Network
-- Load Balancer the load balancer name parameter should be omitted.
loadBalancer_loadBalancerName :: Lens.Lens' LoadBalancer (Prelude.Maybe Prelude.Text)
loadBalancer_loadBalancerName :: (Maybe Text -> f (Maybe Text)) -> LoadBalancer -> f LoadBalancer
loadBalancer_loadBalancerName = (LoadBalancer -> Maybe Text)
-> (LoadBalancer -> Maybe Text -> LoadBalancer)
-> Lens LoadBalancer LoadBalancer (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoadBalancer' {Maybe Text
loadBalancerName :: Maybe Text
$sel:loadBalancerName:LoadBalancer' :: LoadBalancer -> Maybe Text
loadBalancerName} -> Maybe Text
loadBalancerName) (\s :: LoadBalancer
s@LoadBalancer' {} Maybe Text
a -> LoadBalancer
s {$sel:loadBalancerName:LoadBalancer' :: Maybe Text
loadBalancerName = Maybe Text
a} :: LoadBalancer)

-- | The name of the container (as it appears in a container definition) to
-- associate with the load balancer.
loadBalancer_containerName :: Lens.Lens' LoadBalancer (Prelude.Maybe Prelude.Text)
loadBalancer_containerName :: (Maybe Text -> f (Maybe Text)) -> LoadBalancer -> f LoadBalancer
loadBalancer_containerName = (LoadBalancer -> Maybe Text)
-> (LoadBalancer -> Maybe Text -> LoadBalancer)
-> Lens LoadBalancer LoadBalancer (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoadBalancer' {Maybe Text
containerName :: Maybe Text
$sel:containerName:LoadBalancer' :: LoadBalancer -> Maybe Text
containerName} -> Maybe Text
containerName) (\s :: LoadBalancer
s@LoadBalancer' {} Maybe Text
a -> LoadBalancer
s {$sel:containerName:LoadBalancer' :: Maybe Text
containerName = Maybe Text
a} :: LoadBalancer)

-- | The full Amazon Resource Name (ARN) of the Elastic Load Balancing target
-- group or groups associated with a service or task set.
--
-- A target group ARN is only specified when using an Application Load
-- Balancer or Network Load Balancer. If you are using a Classic Load
-- Balancer the target group ARN should be omitted.
--
-- For services using the @ECS@ deployment controller, you can specify one
-- or multiple target groups. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/register-multiple-targetgroups.html Registering Multiple Target Groups with a Service>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- For services using the @CODE_DEPLOY@ deployment controller, you are
-- required to define two target groups for the load balancer. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-bluegreen.html Blue\/Green Deployment with CodeDeploy>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- If your service\'s task definition uses the @awsvpc@ network mode (which
-- is required for the Fargate launch type), you must choose @ip@ as the
-- target type, not @instance@, when creating your target groups because
-- tasks that use the @awsvpc@ network mode are associated with an elastic
-- network interface, not an Amazon EC2 instance.
loadBalancer_targetGroupArn :: Lens.Lens' LoadBalancer (Prelude.Maybe Prelude.Text)
loadBalancer_targetGroupArn :: (Maybe Text -> f (Maybe Text)) -> LoadBalancer -> f LoadBalancer
loadBalancer_targetGroupArn = (LoadBalancer -> Maybe Text)
-> (LoadBalancer -> Maybe Text -> LoadBalancer)
-> Lens LoadBalancer LoadBalancer (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoadBalancer' {Maybe Text
targetGroupArn :: Maybe Text
$sel:targetGroupArn:LoadBalancer' :: LoadBalancer -> Maybe Text
targetGroupArn} -> Maybe Text
targetGroupArn) (\s :: LoadBalancer
s@LoadBalancer' {} Maybe Text
a -> LoadBalancer
s {$sel:targetGroupArn:LoadBalancer' :: Maybe Text
targetGroupArn = Maybe Text
a} :: LoadBalancer)

-- | The port on the container to associate with the load balancer. This port
-- must correspond to a @containerPort@ in the task definition the tasks in
-- the service are using. For tasks that use the EC2 launch type, the
-- container instance they are launched on must allow ingress traffic on
-- the @hostPort@ of the port mapping.
loadBalancer_containerPort :: Lens.Lens' LoadBalancer (Prelude.Maybe Prelude.Int)
loadBalancer_containerPort :: (Maybe Int -> f (Maybe Int)) -> LoadBalancer -> f LoadBalancer
loadBalancer_containerPort = (LoadBalancer -> Maybe Int)
-> (LoadBalancer -> Maybe Int -> LoadBalancer)
-> Lens LoadBalancer LoadBalancer (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoadBalancer' {Maybe Int
containerPort :: Maybe Int
$sel:containerPort:LoadBalancer' :: LoadBalancer -> Maybe Int
containerPort} -> Maybe Int
containerPort) (\s :: LoadBalancer
s@LoadBalancer' {} Maybe Int
a -> LoadBalancer
s {$sel:containerPort:LoadBalancer' :: Maybe Int
containerPort = Maybe Int
a} :: LoadBalancer)

instance Core.FromJSON LoadBalancer where
  parseJSON :: Value -> Parser LoadBalancer
parseJSON =
    String
-> (Object -> Parser LoadBalancer) -> Value -> Parser LoadBalancer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LoadBalancer"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> Maybe Int -> LoadBalancer
LoadBalancer'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Maybe Int -> LoadBalancer)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Maybe Int -> LoadBalancer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"loadBalancerName")
            Parser (Maybe Text -> Maybe Text -> Maybe Int -> LoadBalancer)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Int -> LoadBalancer)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"containerName")
            Parser (Maybe Text -> Maybe Int -> LoadBalancer)
-> Parser (Maybe Text) -> Parser (Maybe Int -> LoadBalancer)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"targetGroupArn")
            Parser (Maybe Int -> LoadBalancer)
-> Parser (Maybe Int) -> Parser LoadBalancer
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"containerPort")
      )

instance Prelude.Hashable LoadBalancer

instance Prelude.NFData LoadBalancer

instance Core.ToJSON LoadBalancer where
  toJSON :: LoadBalancer -> Value
toJSON LoadBalancer' {Maybe Int
Maybe Text
containerPort :: Maybe Int
targetGroupArn :: Maybe Text
containerName :: Maybe Text
loadBalancerName :: Maybe Text
$sel:containerPort:LoadBalancer' :: LoadBalancer -> Maybe Int
$sel:targetGroupArn:LoadBalancer' :: LoadBalancer -> Maybe Text
$sel:containerName:LoadBalancer' :: LoadBalancer -> Maybe Text
$sel:loadBalancerName:LoadBalancer' :: LoadBalancer -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"loadBalancerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
loadBalancerName,
            (Text
"containerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
containerName,
            (Text
"targetGroupArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
targetGroupArn,
            (Text
"containerPort" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
containerPort
          ]
      )