{-# 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.ELBV2.Types.TargetDescription
-- 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.ELBV2.Types.TargetDescription where

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

-- | Information about a target.
--
-- /See:/ 'newTargetDescription' smart constructor.
data TargetDescription = TargetDescription'
  { -- | An Availability Zone or @all@. This determines whether the target
    -- receives traffic from the load balancer nodes in the specified
    -- Availability Zone or from all enabled Availability Zones for the load
    -- balancer.
    --
    -- This parameter is not supported if the target type of the target group
    -- is @instance@ or @alb@.
    --
    -- If the target type is @ip@ and the IP address is in a subnet of the VPC
    -- for the target group, the Availability Zone is automatically detected
    -- and this parameter is optional. If the IP address is outside the VPC,
    -- this parameter is required.
    --
    -- With an Application Load Balancer, if the target type is @ip@ and the IP
    -- address is outside the VPC for the target group, the only supported
    -- value is @all@.
    --
    -- If the target type is @lambda@, this parameter is optional and the only
    -- supported value is @all@.
    TargetDescription -> Maybe Text
availabilityZone :: Prelude.Maybe Prelude.Text,
    -- | The port on which the target is listening. If the target group protocol
    -- is GENEVE, the supported port is 6081. If the target type is @alb@, the
    -- targeted Application Load Balancer must have at least one listener whose
    -- port matches the target group port. Not used if the target is a Lambda
    -- function.
    TargetDescription -> Maybe Natural
port :: Prelude.Maybe Prelude.Natural,
    -- | The ID of the target. If the target type of the target group is
    -- @instance@, specify an instance ID. If the target type is @ip@, specify
    -- an IP address. If the target type is @lambda@, specify the ARN of the
    -- Lambda function. If the target type is @alb@, specify the ARN of the
    -- Application Load Balancer target.
    TargetDescription -> Text
id :: Prelude.Text
  }
  deriving (TargetDescription -> TargetDescription -> Bool
(TargetDescription -> TargetDescription -> Bool)
-> (TargetDescription -> TargetDescription -> Bool)
-> Eq TargetDescription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetDescription -> TargetDescription -> Bool
$c/= :: TargetDescription -> TargetDescription -> Bool
== :: TargetDescription -> TargetDescription -> Bool
$c== :: TargetDescription -> TargetDescription -> Bool
Prelude.Eq, ReadPrec [TargetDescription]
ReadPrec TargetDescription
Int -> ReadS TargetDescription
ReadS [TargetDescription]
(Int -> ReadS TargetDescription)
-> ReadS [TargetDescription]
-> ReadPrec TargetDescription
-> ReadPrec [TargetDescription]
-> Read TargetDescription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetDescription]
$creadListPrec :: ReadPrec [TargetDescription]
readPrec :: ReadPrec TargetDescription
$creadPrec :: ReadPrec TargetDescription
readList :: ReadS [TargetDescription]
$creadList :: ReadS [TargetDescription]
readsPrec :: Int -> ReadS TargetDescription
$creadsPrec :: Int -> ReadS TargetDescription
Prelude.Read, Int -> TargetDescription -> ShowS
[TargetDescription] -> ShowS
TargetDescription -> String
(Int -> TargetDescription -> ShowS)
-> (TargetDescription -> String)
-> ([TargetDescription] -> ShowS)
-> Show TargetDescription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetDescription] -> ShowS
$cshowList :: [TargetDescription] -> ShowS
show :: TargetDescription -> String
$cshow :: TargetDescription -> String
showsPrec :: Int -> TargetDescription -> ShowS
$cshowsPrec :: Int -> TargetDescription -> ShowS
Prelude.Show, (forall x. TargetDescription -> Rep TargetDescription x)
-> (forall x. Rep TargetDescription x -> TargetDescription)
-> Generic TargetDescription
forall x. Rep TargetDescription x -> TargetDescription
forall x. TargetDescription -> Rep TargetDescription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TargetDescription x -> TargetDescription
$cfrom :: forall x. TargetDescription -> Rep TargetDescription x
Prelude.Generic)

-- |
-- Create a value of 'TargetDescription' 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:
--
-- 'availabilityZone', 'targetDescription_availabilityZone' - An Availability Zone or @all@. This determines whether the target
-- receives traffic from the load balancer nodes in the specified
-- Availability Zone or from all enabled Availability Zones for the load
-- balancer.
--
-- This parameter is not supported if the target type of the target group
-- is @instance@ or @alb@.
--
-- If the target type is @ip@ and the IP address is in a subnet of the VPC
-- for the target group, the Availability Zone is automatically detected
-- and this parameter is optional. If the IP address is outside the VPC,
-- this parameter is required.
--
-- With an Application Load Balancer, if the target type is @ip@ and the IP
-- address is outside the VPC for the target group, the only supported
-- value is @all@.
--
-- If the target type is @lambda@, this parameter is optional and the only
-- supported value is @all@.
--
-- 'port', 'targetDescription_port' - The port on which the target is listening. If the target group protocol
-- is GENEVE, the supported port is 6081. If the target type is @alb@, the
-- targeted Application Load Balancer must have at least one listener whose
-- port matches the target group port. Not used if the target is a Lambda
-- function.
--
-- 'id', 'targetDescription_id' - The ID of the target. If the target type of the target group is
-- @instance@, specify an instance ID. If the target type is @ip@, specify
-- an IP address. If the target type is @lambda@, specify the ARN of the
-- Lambda function. If the target type is @alb@, specify the ARN of the
-- Application Load Balancer target.
newTargetDescription ::
  -- | 'id'
  Prelude.Text ->
  TargetDescription
newTargetDescription :: Text -> TargetDescription
newTargetDescription Text
pId_ =
  TargetDescription' :: Maybe Text -> Maybe Natural -> Text -> TargetDescription
TargetDescription'
    { $sel:availabilityZone:TargetDescription' :: Maybe Text
availabilityZone =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:port:TargetDescription' :: Maybe Natural
port = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:id:TargetDescription' :: Text
id = Text
pId_
    }

-- | An Availability Zone or @all@. This determines whether the target
-- receives traffic from the load balancer nodes in the specified
-- Availability Zone or from all enabled Availability Zones for the load
-- balancer.
--
-- This parameter is not supported if the target type of the target group
-- is @instance@ or @alb@.
--
-- If the target type is @ip@ and the IP address is in a subnet of the VPC
-- for the target group, the Availability Zone is automatically detected
-- and this parameter is optional. If the IP address is outside the VPC,
-- this parameter is required.
--
-- With an Application Load Balancer, if the target type is @ip@ and the IP
-- address is outside the VPC for the target group, the only supported
-- value is @all@.
--
-- If the target type is @lambda@, this parameter is optional and the only
-- supported value is @all@.
targetDescription_availabilityZone :: Lens.Lens' TargetDescription (Prelude.Maybe Prelude.Text)
targetDescription_availabilityZone :: (Maybe Text -> f (Maybe Text))
-> TargetDescription -> f TargetDescription
targetDescription_availabilityZone = (TargetDescription -> Maybe Text)
-> (TargetDescription -> Maybe Text -> TargetDescription)
-> Lens
     TargetDescription TargetDescription (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetDescription' {Maybe Text
availabilityZone :: Maybe Text
$sel:availabilityZone:TargetDescription' :: TargetDescription -> Maybe Text
availabilityZone} -> Maybe Text
availabilityZone) (\s :: TargetDescription
s@TargetDescription' {} Maybe Text
a -> TargetDescription
s {$sel:availabilityZone:TargetDescription' :: Maybe Text
availabilityZone = Maybe Text
a} :: TargetDescription)

-- | The port on which the target is listening. If the target group protocol
-- is GENEVE, the supported port is 6081. If the target type is @alb@, the
-- targeted Application Load Balancer must have at least one listener whose
-- port matches the target group port. Not used if the target is a Lambda
-- function.
targetDescription_port :: Lens.Lens' TargetDescription (Prelude.Maybe Prelude.Natural)
targetDescription_port :: (Maybe Natural -> f (Maybe Natural))
-> TargetDescription -> f TargetDescription
targetDescription_port = (TargetDescription -> Maybe Natural)
-> (TargetDescription -> Maybe Natural -> TargetDescription)
-> Lens
     TargetDescription TargetDescription (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetDescription' {Maybe Natural
port :: Maybe Natural
$sel:port:TargetDescription' :: TargetDescription -> Maybe Natural
port} -> Maybe Natural
port) (\s :: TargetDescription
s@TargetDescription' {} Maybe Natural
a -> TargetDescription
s {$sel:port:TargetDescription' :: Maybe Natural
port = Maybe Natural
a} :: TargetDescription)

-- | The ID of the target. If the target type of the target group is
-- @instance@, specify an instance ID. If the target type is @ip@, specify
-- an IP address. If the target type is @lambda@, specify the ARN of the
-- Lambda function. If the target type is @alb@, specify the ARN of the
-- Application Load Balancer target.
targetDescription_id :: Lens.Lens' TargetDescription Prelude.Text
targetDescription_id :: (Text -> f Text) -> TargetDescription -> f TargetDescription
targetDescription_id = (TargetDescription -> Text)
-> (TargetDescription -> Text -> TargetDescription)
-> Lens TargetDescription TargetDescription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetDescription' {Text
id :: Text
$sel:id:TargetDescription' :: TargetDescription -> Text
id} -> Text
id) (\s :: TargetDescription
s@TargetDescription' {} Text
a -> TargetDescription
s {$sel:id:TargetDescription' :: Text
id = Text
a} :: TargetDescription)

instance Core.FromXML TargetDescription where
  parseXML :: [Node] -> Either String TargetDescription
parseXML [Node]
x =
    Maybe Text -> Maybe Natural -> Text -> TargetDescription
TargetDescription'
      (Maybe Text -> Maybe Natural -> Text -> TargetDescription)
-> Either String (Maybe Text)
-> Either String (Maybe Natural -> Text -> TargetDescription)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"AvailabilityZone")
      Either String (Maybe Natural -> Text -> TargetDescription)
-> Either String (Maybe Natural)
-> Either String (Text -> TargetDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Natural)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Port")
      Either String (Text -> TargetDescription)
-> Either String Text -> Either String TargetDescription
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Id")

instance Prelude.Hashable TargetDescription

instance Prelude.NFData TargetDescription

instance Core.ToQuery TargetDescription where
  toQuery :: TargetDescription -> QueryString
toQuery TargetDescription' {Maybe Natural
Maybe Text
Text
id :: Text
port :: Maybe Natural
availabilityZone :: Maybe Text
$sel:id:TargetDescription' :: TargetDescription -> Text
$sel:port:TargetDescription' :: TargetDescription -> Maybe Natural
$sel:availabilityZone:TargetDescription' :: TargetDescription -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"AvailabilityZone" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
availabilityZone,
        ByteString
"Port" ByteString -> Maybe Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Natural
port,
        ByteString
"Id" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
id
      ]