{-# 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.GlobalAccelerator.Types.EndpointConfiguration
-- 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.GlobalAccelerator.Types.EndpointConfiguration where

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

-- | A complex type for endpoints. A resource must be valid and active when
-- you add it as an endpoint.
--
-- /See:/ 'newEndpointConfiguration' smart constructor.
data EndpointConfiguration = EndpointConfiguration'
  { -- | The weight associated with the endpoint. When you add weights to
    -- endpoints, you configure AWS Global Accelerator to route traffic based
    -- on proportions that you specify. For example, you might specify endpoint
    -- weights of 4, 5, 5, and 6 (sum=20). The result is that 4\/20 of your
    -- traffic, on average, is routed to the first endpoint, 5\/20 is routed
    -- both to the second and third endpoints, and 6\/20 is routed to the last
    -- endpoint. For more information, see
    -- <https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoints-endpoint-weights.html Endpoint Weights>
    -- in the /AWS Global Accelerator Developer Guide/.
    EndpointConfiguration -> Maybe Natural
weight :: Prelude.Maybe Prelude.Natural,
    -- | Indicates whether client IP address preservation is enabled for an
    -- Application Load Balancer endpoint. The value is true or false. The
    -- default value is true for new accelerators.
    --
    -- If the value is set to true, the client\'s IP address is preserved in
    -- the @X-Forwarded-For@ request header as traffic travels to applications
    -- on the Application Load Balancer endpoint fronted by the accelerator.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/global-accelerator/latest/dg/preserve-client-ip-address.html Preserve Client IP Addresses in AWS Global Accelerator>
    -- in the /AWS Global Accelerator Developer Guide/.
    EndpointConfiguration -> Maybe Bool
clientIPPreservationEnabled :: Prelude.Maybe Prelude.Bool,
    -- | An ID for the endpoint. If the endpoint is a Network Load Balancer or
    -- Application Load Balancer, this is the Amazon Resource Name (ARN) of the
    -- resource. If the endpoint is an Elastic IP address, this is the Elastic
    -- IP address allocation ID. For Amazon EC2 instances, this is the EC2
    -- instance ID. A resource must be valid and active when you add it as an
    -- endpoint.
    --
    -- An Application Load Balancer can be either internal or internet-facing.
    EndpointConfiguration -> Maybe Text
endpointId :: Prelude.Maybe Prelude.Text
  }
  deriving (EndpointConfiguration -> EndpointConfiguration -> Bool
(EndpointConfiguration -> EndpointConfiguration -> Bool)
-> (EndpointConfiguration -> EndpointConfiguration -> Bool)
-> Eq EndpointConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EndpointConfiguration -> EndpointConfiguration -> Bool
$c/= :: EndpointConfiguration -> EndpointConfiguration -> Bool
== :: EndpointConfiguration -> EndpointConfiguration -> Bool
$c== :: EndpointConfiguration -> EndpointConfiguration -> Bool
Prelude.Eq, ReadPrec [EndpointConfiguration]
ReadPrec EndpointConfiguration
Int -> ReadS EndpointConfiguration
ReadS [EndpointConfiguration]
(Int -> ReadS EndpointConfiguration)
-> ReadS [EndpointConfiguration]
-> ReadPrec EndpointConfiguration
-> ReadPrec [EndpointConfiguration]
-> Read EndpointConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EndpointConfiguration]
$creadListPrec :: ReadPrec [EndpointConfiguration]
readPrec :: ReadPrec EndpointConfiguration
$creadPrec :: ReadPrec EndpointConfiguration
readList :: ReadS [EndpointConfiguration]
$creadList :: ReadS [EndpointConfiguration]
readsPrec :: Int -> ReadS EndpointConfiguration
$creadsPrec :: Int -> ReadS EndpointConfiguration
Prelude.Read, Int -> EndpointConfiguration -> ShowS
[EndpointConfiguration] -> ShowS
EndpointConfiguration -> String
(Int -> EndpointConfiguration -> ShowS)
-> (EndpointConfiguration -> String)
-> ([EndpointConfiguration] -> ShowS)
-> Show EndpointConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EndpointConfiguration] -> ShowS
$cshowList :: [EndpointConfiguration] -> ShowS
show :: EndpointConfiguration -> String
$cshow :: EndpointConfiguration -> String
showsPrec :: Int -> EndpointConfiguration -> ShowS
$cshowsPrec :: Int -> EndpointConfiguration -> ShowS
Prelude.Show, (forall x. EndpointConfiguration -> Rep EndpointConfiguration x)
-> (forall x. Rep EndpointConfiguration x -> EndpointConfiguration)
-> Generic EndpointConfiguration
forall x. Rep EndpointConfiguration x -> EndpointConfiguration
forall x. EndpointConfiguration -> Rep EndpointConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EndpointConfiguration x -> EndpointConfiguration
$cfrom :: forall x. EndpointConfiguration -> Rep EndpointConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'EndpointConfiguration' 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:
--
-- 'weight', 'endpointConfiguration_weight' - The weight associated with the endpoint. When you add weights to
-- endpoints, you configure AWS Global Accelerator to route traffic based
-- on proportions that you specify. For example, you might specify endpoint
-- weights of 4, 5, 5, and 6 (sum=20). The result is that 4\/20 of your
-- traffic, on average, is routed to the first endpoint, 5\/20 is routed
-- both to the second and third endpoints, and 6\/20 is routed to the last
-- endpoint. For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoints-endpoint-weights.html Endpoint Weights>
-- in the /AWS Global Accelerator Developer Guide/.
--
-- 'clientIPPreservationEnabled', 'endpointConfiguration_clientIPPreservationEnabled' - Indicates whether client IP address preservation is enabled for an
-- Application Load Balancer endpoint. The value is true or false. The
-- default value is true for new accelerators.
--
-- If the value is set to true, the client\'s IP address is preserved in
-- the @X-Forwarded-For@ request header as traffic travels to applications
-- on the Application Load Balancer endpoint fronted by the accelerator.
--
-- For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/preserve-client-ip-address.html Preserve Client IP Addresses in AWS Global Accelerator>
-- in the /AWS Global Accelerator Developer Guide/.
--
-- 'endpointId', 'endpointConfiguration_endpointId' - An ID for the endpoint. If the endpoint is a Network Load Balancer or
-- Application Load Balancer, this is the Amazon Resource Name (ARN) of the
-- resource. If the endpoint is an Elastic IP address, this is the Elastic
-- IP address allocation ID. For Amazon EC2 instances, this is the EC2
-- instance ID. A resource must be valid and active when you add it as an
-- endpoint.
--
-- An Application Load Balancer can be either internal or internet-facing.
newEndpointConfiguration ::
  EndpointConfiguration
newEndpointConfiguration :: EndpointConfiguration
newEndpointConfiguration =
  EndpointConfiguration' :: Maybe Natural -> Maybe Bool -> Maybe Text -> EndpointConfiguration
EndpointConfiguration'
    { $sel:weight:EndpointConfiguration' :: Maybe Natural
weight = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:clientIPPreservationEnabled:EndpointConfiguration' :: Maybe Bool
clientIPPreservationEnabled = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:endpointId:EndpointConfiguration' :: Maybe Text
endpointId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The weight associated with the endpoint. When you add weights to
-- endpoints, you configure AWS Global Accelerator to route traffic based
-- on proportions that you specify. For example, you might specify endpoint
-- weights of 4, 5, 5, and 6 (sum=20). The result is that 4\/20 of your
-- traffic, on average, is routed to the first endpoint, 5\/20 is routed
-- both to the second and third endpoints, and 6\/20 is routed to the last
-- endpoint. For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoints-endpoint-weights.html Endpoint Weights>
-- in the /AWS Global Accelerator Developer Guide/.
endpointConfiguration_weight :: Lens.Lens' EndpointConfiguration (Prelude.Maybe Prelude.Natural)
endpointConfiguration_weight :: (Maybe Natural -> f (Maybe Natural))
-> EndpointConfiguration -> f EndpointConfiguration
endpointConfiguration_weight = (EndpointConfiguration -> Maybe Natural)
-> (EndpointConfiguration
    -> Maybe Natural -> EndpointConfiguration)
-> Lens
     EndpointConfiguration
     EndpointConfiguration
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointConfiguration' {Maybe Natural
weight :: Maybe Natural
$sel:weight:EndpointConfiguration' :: EndpointConfiguration -> Maybe Natural
weight} -> Maybe Natural
weight) (\s :: EndpointConfiguration
s@EndpointConfiguration' {} Maybe Natural
a -> EndpointConfiguration
s {$sel:weight:EndpointConfiguration' :: Maybe Natural
weight = Maybe Natural
a} :: EndpointConfiguration)

-- | Indicates whether client IP address preservation is enabled for an
-- Application Load Balancer endpoint. The value is true or false. The
-- default value is true for new accelerators.
--
-- If the value is set to true, the client\'s IP address is preserved in
-- the @X-Forwarded-For@ request header as traffic travels to applications
-- on the Application Load Balancer endpoint fronted by the accelerator.
--
-- For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/preserve-client-ip-address.html Preserve Client IP Addresses in AWS Global Accelerator>
-- in the /AWS Global Accelerator Developer Guide/.
endpointConfiguration_clientIPPreservationEnabled :: Lens.Lens' EndpointConfiguration (Prelude.Maybe Prelude.Bool)
endpointConfiguration_clientIPPreservationEnabled :: (Maybe Bool -> f (Maybe Bool))
-> EndpointConfiguration -> f EndpointConfiguration
endpointConfiguration_clientIPPreservationEnabled = (EndpointConfiguration -> Maybe Bool)
-> (EndpointConfiguration -> Maybe Bool -> EndpointConfiguration)
-> Lens
     EndpointConfiguration
     EndpointConfiguration
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointConfiguration' {Maybe Bool
clientIPPreservationEnabled :: Maybe Bool
$sel:clientIPPreservationEnabled:EndpointConfiguration' :: EndpointConfiguration -> Maybe Bool
clientIPPreservationEnabled} -> Maybe Bool
clientIPPreservationEnabled) (\s :: EndpointConfiguration
s@EndpointConfiguration' {} Maybe Bool
a -> EndpointConfiguration
s {$sel:clientIPPreservationEnabled:EndpointConfiguration' :: Maybe Bool
clientIPPreservationEnabled = Maybe Bool
a} :: EndpointConfiguration)

-- | An ID for the endpoint. If the endpoint is a Network Load Balancer or
-- Application Load Balancer, this is the Amazon Resource Name (ARN) of the
-- resource. If the endpoint is an Elastic IP address, this is the Elastic
-- IP address allocation ID. For Amazon EC2 instances, this is the EC2
-- instance ID. A resource must be valid and active when you add it as an
-- endpoint.
--
-- An Application Load Balancer can be either internal or internet-facing.
endpointConfiguration_endpointId :: Lens.Lens' EndpointConfiguration (Prelude.Maybe Prelude.Text)
endpointConfiguration_endpointId :: (Maybe Text -> f (Maybe Text))
-> EndpointConfiguration -> f EndpointConfiguration
endpointConfiguration_endpointId = (EndpointConfiguration -> Maybe Text)
-> (EndpointConfiguration -> Maybe Text -> EndpointConfiguration)
-> Lens
     EndpointConfiguration
     EndpointConfiguration
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EndpointConfiguration' {Maybe Text
endpointId :: Maybe Text
$sel:endpointId:EndpointConfiguration' :: EndpointConfiguration -> Maybe Text
endpointId} -> Maybe Text
endpointId) (\s :: EndpointConfiguration
s@EndpointConfiguration' {} Maybe Text
a -> EndpointConfiguration
s {$sel:endpointId:EndpointConfiguration' :: Maybe Text
endpointId = Maybe Text
a} :: EndpointConfiguration)

instance Prelude.Hashable EndpointConfiguration

instance Prelude.NFData EndpointConfiguration

instance Core.ToJSON EndpointConfiguration where
  toJSON :: EndpointConfiguration -> Value
toJSON EndpointConfiguration' {Maybe Bool
Maybe Natural
Maybe Text
endpointId :: Maybe Text
clientIPPreservationEnabled :: Maybe Bool
weight :: Maybe Natural
$sel:endpointId:EndpointConfiguration' :: EndpointConfiguration -> Maybe Text
$sel:clientIPPreservationEnabled:EndpointConfiguration' :: EndpointConfiguration -> Maybe Bool
$sel:weight:EndpointConfiguration' :: EndpointConfiguration -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Weight" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
weight,
            (Text
"ClientIPPreservationEnabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
clientIPPreservationEnabled,
            (Text
"EndpointId" 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
endpointId
          ]
      )