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

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

-- |
-- Module      : Amazonka.ELB.AttachLoadBalancerToSubnets
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds one or more subnets to the set of configured subnets for the
-- specified load balancer.
--
-- The load balancer evenly distributes requests across all registered
-- subnets. For more information, see
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-manage-subnets.html Add or Remove Subnets for Your Load Balancer in a VPC>
-- in the /Classic Load Balancers Guide/.
module Amazonka.ELB.AttachLoadBalancerToSubnets
  ( -- * Creating a Request
    AttachLoadBalancerToSubnets (..),
    newAttachLoadBalancerToSubnets,

    -- * Request Lenses
    attachLoadBalancerToSubnets_loadBalancerName,
    attachLoadBalancerToSubnets_subnets,

    -- * Destructuring the Response
    AttachLoadBalancerToSubnetsResponse (..),
    newAttachLoadBalancerToSubnetsResponse,

    -- * Response Lenses
    attachLoadBalancerToSubnetsResponse_subnets,
    attachLoadBalancerToSubnetsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ELB.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Contains the parameters for AttachLoaBalancerToSubnets.
--
-- /See:/ 'newAttachLoadBalancerToSubnets' smart constructor.
data AttachLoadBalancerToSubnets = AttachLoadBalancerToSubnets'
  { -- | The name of the load balancer.
    AttachLoadBalancerToSubnets -> Text
loadBalancerName :: Prelude.Text,
    -- | The IDs of the subnets to add. You can add only one subnet per
    -- Availability Zone.
    AttachLoadBalancerToSubnets -> [Text]
subnets :: [Prelude.Text]
  }
  deriving (AttachLoadBalancerToSubnets -> AttachLoadBalancerToSubnets -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachLoadBalancerToSubnets -> AttachLoadBalancerToSubnets -> Bool
$c/= :: AttachLoadBalancerToSubnets -> AttachLoadBalancerToSubnets -> Bool
== :: AttachLoadBalancerToSubnets -> AttachLoadBalancerToSubnets -> Bool
$c== :: AttachLoadBalancerToSubnets -> AttachLoadBalancerToSubnets -> Bool
Prelude.Eq, ReadPrec [AttachLoadBalancerToSubnets]
ReadPrec AttachLoadBalancerToSubnets
Int -> ReadS AttachLoadBalancerToSubnets
ReadS [AttachLoadBalancerToSubnets]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachLoadBalancerToSubnets]
$creadListPrec :: ReadPrec [AttachLoadBalancerToSubnets]
readPrec :: ReadPrec AttachLoadBalancerToSubnets
$creadPrec :: ReadPrec AttachLoadBalancerToSubnets
readList :: ReadS [AttachLoadBalancerToSubnets]
$creadList :: ReadS [AttachLoadBalancerToSubnets]
readsPrec :: Int -> ReadS AttachLoadBalancerToSubnets
$creadsPrec :: Int -> ReadS AttachLoadBalancerToSubnets
Prelude.Read, Int -> AttachLoadBalancerToSubnets -> ShowS
[AttachLoadBalancerToSubnets] -> ShowS
AttachLoadBalancerToSubnets -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachLoadBalancerToSubnets] -> ShowS
$cshowList :: [AttachLoadBalancerToSubnets] -> ShowS
show :: AttachLoadBalancerToSubnets -> String
$cshow :: AttachLoadBalancerToSubnets -> String
showsPrec :: Int -> AttachLoadBalancerToSubnets -> ShowS
$cshowsPrec :: Int -> AttachLoadBalancerToSubnets -> ShowS
Prelude.Show, forall x.
Rep AttachLoadBalancerToSubnets x -> AttachLoadBalancerToSubnets
forall x.
AttachLoadBalancerToSubnets -> Rep AttachLoadBalancerToSubnets x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AttachLoadBalancerToSubnets x -> AttachLoadBalancerToSubnets
$cfrom :: forall x.
AttachLoadBalancerToSubnets -> Rep AttachLoadBalancerToSubnets x
Prelude.Generic)

-- |
-- Create a value of 'AttachLoadBalancerToSubnets' 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', 'attachLoadBalancerToSubnets_loadBalancerName' - The name of the load balancer.
--
-- 'subnets', 'attachLoadBalancerToSubnets_subnets' - The IDs of the subnets to add. You can add only one subnet per
-- Availability Zone.
newAttachLoadBalancerToSubnets ::
  -- | 'loadBalancerName'
  Prelude.Text ->
  AttachLoadBalancerToSubnets
newAttachLoadBalancerToSubnets :: Text -> AttachLoadBalancerToSubnets
newAttachLoadBalancerToSubnets Text
pLoadBalancerName_ =
  AttachLoadBalancerToSubnets'
    { $sel:loadBalancerName:AttachLoadBalancerToSubnets' :: Text
loadBalancerName =
        Text
pLoadBalancerName_,
      $sel:subnets:AttachLoadBalancerToSubnets' :: [Text]
subnets = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the load balancer.
attachLoadBalancerToSubnets_loadBalancerName :: Lens.Lens' AttachLoadBalancerToSubnets Prelude.Text
attachLoadBalancerToSubnets_loadBalancerName :: Lens' AttachLoadBalancerToSubnets Text
attachLoadBalancerToSubnets_loadBalancerName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachLoadBalancerToSubnets' {Text
loadBalancerName :: Text
$sel:loadBalancerName:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> Text
loadBalancerName} -> Text
loadBalancerName) (\s :: AttachLoadBalancerToSubnets
s@AttachLoadBalancerToSubnets' {} Text
a -> AttachLoadBalancerToSubnets
s {$sel:loadBalancerName:AttachLoadBalancerToSubnets' :: Text
loadBalancerName = Text
a} :: AttachLoadBalancerToSubnets)

-- | The IDs of the subnets to add. You can add only one subnet per
-- Availability Zone.
attachLoadBalancerToSubnets_subnets :: Lens.Lens' AttachLoadBalancerToSubnets [Prelude.Text]
attachLoadBalancerToSubnets_subnets :: Lens' AttachLoadBalancerToSubnets [Text]
attachLoadBalancerToSubnets_subnets = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachLoadBalancerToSubnets' {[Text]
subnets :: [Text]
$sel:subnets:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> [Text]
subnets} -> [Text]
subnets) (\s :: AttachLoadBalancerToSubnets
s@AttachLoadBalancerToSubnets' {} [Text]
a -> AttachLoadBalancerToSubnets
s {$sel:subnets:AttachLoadBalancerToSubnets' :: [Text]
subnets = [Text]
a} :: AttachLoadBalancerToSubnets) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest AttachLoadBalancerToSubnets where
  type
    AWSResponse AttachLoadBalancerToSubnets =
      AttachLoadBalancerToSubnetsResponse
  request :: (Service -> Service)
-> AttachLoadBalancerToSubnets
-> Request AttachLoadBalancerToSubnets
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AttachLoadBalancerToSubnets
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AttachLoadBalancerToSubnets)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"AttachLoadBalancerToSubnetsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [Text] -> Int -> AttachLoadBalancerToSubnetsResponse
AttachLoadBalancerToSubnetsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                            forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Subnets"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                            forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member")
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AttachLoadBalancerToSubnets where
  hashWithSalt :: Int -> AttachLoadBalancerToSubnets -> Int
hashWithSalt Int
_salt AttachLoadBalancerToSubnets' {[Text]
Text
subnets :: [Text]
loadBalancerName :: Text
$sel:subnets:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> [Text]
$sel:loadBalancerName:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
loadBalancerName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
subnets

instance Prelude.NFData AttachLoadBalancerToSubnets where
  rnf :: AttachLoadBalancerToSubnets -> ()
rnf AttachLoadBalancerToSubnets' {[Text]
Text
subnets :: [Text]
loadBalancerName :: Text
$sel:subnets:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> [Text]
$sel:loadBalancerName:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
loadBalancerName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
subnets

instance Data.ToHeaders AttachLoadBalancerToSubnets where
  toHeaders :: AttachLoadBalancerToSubnets -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath AttachLoadBalancerToSubnets where
  toPath :: AttachLoadBalancerToSubnets -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery AttachLoadBalancerToSubnets where
  toQuery :: AttachLoadBalancerToSubnets -> QueryString
toQuery AttachLoadBalancerToSubnets' {[Text]
Text
subnets :: [Text]
loadBalancerName :: Text
$sel:subnets:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> [Text]
$sel:loadBalancerName:AttachLoadBalancerToSubnets' :: AttachLoadBalancerToSubnets -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: ( ByteString
"AttachLoadBalancerToSubnets" ::
                      Prelude.ByteString
                  ),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2012-06-01" :: Prelude.ByteString),
        ByteString
"LoadBalancerName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
loadBalancerName,
        ByteString
"Subnets" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"member" [Text]
subnets
      ]

-- | Contains the output of AttachLoadBalancerToSubnets.
--
-- /See:/ 'newAttachLoadBalancerToSubnetsResponse' smart constructor.
data AttachLoadBalancerToSubnetsResponse = AttachLoadBalancerToSubnetsResponse'
  { -- | The IDs of the subnets attached to the load balancer.
    AttachLoadBalancerToSubnetsResponse -> Maybe [Text]
subnets :: Prelude.Maybe [Prelude.Text],
    -- | The response's http status code.
    AttachLoadBalancerToSubnetsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AttachLoadBalancerToSubnetsResponse
-> AttachLoadBalancerToSubnetsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachLoadBalancerToSubnetsResponse
-> AttachLoadBalancerToSubnetsResponse -> Bool
$c/= :: AttachLoadBalancerToSubnetsResponse
-> AttachLoadBalancerToSubnetsResponse -> Bool
== :: AttachLoadBalancerToSubnetsResponse
-> AttachLoadBalancerToSubnetsResponse -> Bool
$c== :: AttachLoadBalancerToSubnetsResponse
-> AttachLoadBalancerToSubnetsResponse -> Bool
Prelude.Eq, ReadPrec [AttachLoadBalancerToSubnetsResponse]
ReadPrec AttachLoadBalancerToSubnetsResponse
Int -> ReadS AttachLoadBalancerToSubnetsResponse
ReadS [AttachLoadBalancerToSubnetsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachLoadBalancerToSubnetsResponse]
$creadListPrec :: ReadPrec [AttachLoadBalancerToSubnetsResponse]
readPrec :: ReadPrec AttachLoadBalancerToSubnetsResponse
$creadPrec :: ReadPrec AttachLoadBalancerToSubnetsResponse
readList :: ReadS [AttachLoadBalancerToSubnetsResponse]
$creadList :: ReadS [AttachLoadBalancerToSubnetsResponse]
readsPrec :: Int -> ReadS AttachLoadBalancerToSubnetsResponse
$creadsPrec :: Int -> ReadS AttachLoadBalancerToSubnetsResponse
Prelude.Read, Int -> AttachLoadBalancerToSubnetsResponse -> ShowS
[AttachLoadBalancerToSubnetsResponse] -> ShowS
AttachLoadBalancerToSubnetsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachLoadBalancerToSubnetsResponse] -> ShowS
$cshowList :: [AttachLoadBalancerToSubnetsResponse] -> ShowS
show :: AttachLoadBalancerToSubnetsResponse -> String
$cshow :: AttachLoadBalancerToSubnetsResponse -> String
showsPrec :: Int -> AttachLoadBalancerToSubnetsResponse -> ShowS
$cshowsPrec :: Int -> AttachLoadBalancerToSubnetsResponse -> ShowS
Prelude.Show, forall x.
Rep AttachLoadBalancerToSubnetsResponse x
-> AttachLoadBalancerToSubnetsResponse
forall x.
AttachLoadBalancerToSubnetsResponse
-> Rep AttachLoadBalancerToSubnetsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AttachLoadBalancerToSubnetsResponse x
-> AttachLoadBalancerToSubnetsResponse
$cfrom :: forall x.
AttachLoadBalancerToSubnetsResponse
-> Rep AttachLoadBalancerToSubnetsResponse x
Prelude.Generic)

-- |
-- Create a value of 'AttachLoadBalancerToSubnetsResponse' 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:
--
-- 'subnets', 'attachLoadBalancerToSubnetsResponse_subnets' - The IDs of the subnets attached to the load balancer.
--
-- 'httpStatus', 'attachLoadBalancerToSubnetsResponse_httpStatus' - The response's http status code.
newAttachLoadBalancerToSubnetsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AttachLoadBalancerToSubnetsResponse
newAttachLoadBalancerToSubnetsResponse :: Int -> AttachLoadBalancerToSubnetsResponse
newAttachLoadBalancerToSubnetsResponse Int
pHttpStatus_ =
  AttachLoadBalancerToSubnetsResponse'
    { $sel:subnets:AttachLoadBalancerToSubnetsResponse' :: Maybe [Text]
subnets =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AttachLoadBalancerToSubnetsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The IDs of the subnets attached to the load balancer.
attachLoadBalancerToSubnetsResponse_subnets :: Lens.Lens' AttachLoadBalancerToSubnetsResponse (Prelude.Maybe [Prelude.Text])
attachLoadBalancerToSubnetsResponse_subnets :: Lens' AttachLoadBalancerToSubnetsResponse (Maybe [Text])
attachLoadBalancerToSubnetsResponse_subnets = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachLoadBalancerToSubnetsResponse' {Maybe [Text]
subnets :: Maybe [Text]
$sel:subnets:AttachLoadBalancerToSubnetsResponse' :: AttachLoadBalancerToSubnetsResponse -> Maybe [Text]
subnets} -> Maybe [Text]
subnets) (\s :: AttachLoadBalancerToSubnetsResponse
s@AttachLoadBalancerToSubnetsResponse' {} Maybe [Text]
a -> AttachLoadBalancerToSubnetsResponse
s {$sel:subnets:AttachLoadBalancerToSubnetsResponse' :: Maybe [Text]
subnets = Maybe [Text]
a} :: AttachLoadBalancerToSubnetsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
attachLoadBalancerToSubnetsResponse_httpStatus :: Lens.Lens' AttachLoadBalancerToSubnetsResponse Prelude.Int
attachLoadBalancerToSubnetsResponse_httpStatus :: Lens' AttachLoadBalancerToSubnetsResponse Int
attachLoadBalancerToSubnetsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachLoadBalancerToSubnetsResponse' {Int
httpStatus :: Int
$sel:httpStatus:AttachLoadBalancerToSubnetsResponse' :: AttachLoadBalancerToSubnetsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AttachLoadBalancerToSubnetsResponse
s@AttachLoadBalancerToSubnetsResponse' {} Int
a -> AttachLoadBalancerToSubnetsResponse
s {$sel:httpStatus:AttachLoadBalancerToSubnetsResponse' :: Int
httpStatus = Int
a} :: AttachLoadBalancerToSubnetsResponse)

instance
  Prelude.NFData
    AttachLoadBalancerToSubnetsResponse
  where
  rnf :: AttachLoadBalancerToSubnetsResponse -> ()
rnf AttachLoadBalancerToSubnetsResponse' {Int
Maybe [Text]
httpStatus :: Int
subnets :: Maybe [Text]
$sel:httpStatus:AttachLoadBalancerToSubnetsResponse' :: AttachLoadBalancerToSubnetsResponse -> Int
$sel:subnets:AttachLoadBalancerToSubnetsResponse' :: AttachLoadBalancerToSubnetsResponse -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
subnets
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus