{-# 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.AutoScaling.AttachLoadBalancers
-- 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)
--
-- To attach an Application Load Balancer, Network Load Balancer, or
-- Gateway Load Balancer, use the AttachLoadBalancerTargetGroups API
-- operation instead.
--
-- Attaches one or more Classic Load Balancers to the specified Auto
-- Scaling group. Amazon EC2 Auto Scaling registers the running instances
-- with these Classic Load Balancers.
--
-- To describe the load balancers for an Auto Scaling group, call the
-- DescribeLoadBalancers API. To detach the load balancer from the Auto
-- Scaling group, call the DetachLoadBalancers API.
--
-- For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/autoscaling-load-balancer.html Elastic Load Balancing and Amazon EC2 Auto Scaling>
-- in the /Amazon EC2 Auto Scaling User Guide/.
module Amazonka.AutoScaling.AttachLoadBalancers
  ( -- * Creating a Request
    AttachLoadBalancers (..),
    newAttachLoadBalancers,

    -- * Request Lenses
    attachLoadBalancers_autoScalingGroupName,
    attachLoadBalancers_loadBalancerNames,

    -- * Destructuring the Response
    AttachLoadBalancersResponse (..),
    newAttachLoadBalancersResponse,

    -- * Response Lenses
    attachLoadBalancersResponse_httpStatus,
  )
where

import Amazonka.AutoScaling.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAttachLoadBalancers' smart constructor.
data AttachLoadBalancers = AttachLoadBalancers'
  { -- | The name of the Auto Scaling group.
    AttachLoadBalancers -> Text
autoScalingGroupName :: Prelude.Text,
    -- | The names of the load balancers. You can specify up to 10 load
    -- balancers.
    AttachLoadBalancers -> [Text]
loadBalancerNames :: [Prelude.Text]
  }
  deriving (AttachLoadBalancers -> AttachLoadBalancers -> Bool
(AttachLoadBalancers -> AttachLoadBalancers -> Bool)
-> (AttachLoadBalancers -> AttachLoadBalancers -> Bool)
-> Eq AttachLoadBalancers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachLoadBalancers -> AttachLoadBalancers -> Bool
$c/= :: AttachLoadBalancers -> AttachLoadBalancers -> Bool
== :: AttachLoadBalancers -> AttachLoadBalancers -> Bool
$c== :: AttachLoadBalancers -> AttachLoadBalancers -> Bool
Prelude.Eq, ReadPrec [AttachLoadBalancers]
ReadPrec AttachLoadBalancers
Int -> ReadS AttachLoadBalancers
ReadS [AttachLoadBalancers]
(Int -> ReadS AttachLoadBalancers)
-> ReadS [AttachLoadBalancers]
-> ReadPrec AttachLoadBalancers
-> ReadPrec [AttachLoadBalancers]
-> Read AttachLoadBalancers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachLoadBalancers]
$creadListPrec :: ReadPrec [AttachLoadBalancers]
readPrec :: ReadPrec AttachLoadBalancers
$creadPrec :: ReadPrec AttachLoadBalancers
readList :: ReadS [AttachLoadBalancers]
$creadList :: ReadS [AttachLoadBalancers]
readsPrec :: Int -> ReadS AttachLoadBalancers
$creadsPrec :: Int -> ReadS AttachLoadBalancers
Prelude.Read, Int -> AttachLoadBalancers -> ShowS
[AttachLoadBalancers] -> ShowS
AttachLoadBalancers -> String
(Int -> AttachLoadBalancers -> ShowS)
-> (AttachLoadBalancers -> String)
-> ([AttachLoadBalancers] -> ShowS)
-> Show AttachLoadBalancers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachLoadBalancers] -> ShowS
$cshowList :: [AttachLoadBalancers] -> ShowS
show :: AttachLoadBalancers -> String
$cshow :: AttachLoadBalancers -> String
showsPrec :: Int -> AttachLoadBalancers -> ShowS
$cshowsPrec :: Int -> AttachLoadBalancers -> ShowS
Prelude.Show, (forall x. AttachLoadBalancers -> Rep AttachLoadBalancers x)
-> (forall x. Rep AttachLoadBalancers x -> AttachLoadBalancers)
-> Generic AttachLoadBalancers
forall x. Rep AttachLoadBalancers x -> AttachLoadBalancers
forall x. AttachLoadBalancers -> Rep AttachLoadBalancers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachLoadBalancers x -> AttachLoadBalancers
$cfrom :: forall x. AttachLoadBalancers -> Rep AttachLoadBalancers x
Prelude.Generic)

-- |
-- Create a value of 'AttachLoadBalancers' 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:
--
-- 'autoScalingGroupName', 'attachLoadBalancers_autoScalingGroupName' - The name of the Auto Scaling group.
--
-- 'loadBalancerNames', 'attachLoadBalancers_loadBalancerNames' - The names of the load balancers. You can specify up to 10 load
-- balancers.
newAttachLoadBalancers ::
  -- | 'autoScalingGroupName'
  Prelude.Text ->
  AttachLoadBalancers
newAttachLoadBalancers :: Text -> AttachLoadBalancers
newAttachLoadBalancers Text
pAutoScalingGroupName_ =
  AttachLoadBalancers' :: Text -> [Text] -> AttachLoadBalancers
AttachLoadBalancers'
    { $sel:autoScalingGroupName:AttachLoadBalancers' :: Text
autoScalingGroupName =
        Text
pAutoScalingGroupName_,
      $sel:loadBalancerNames:AttachLoadBalancers' :: [Text]
loadBalancerNames = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the Auto Scaling group.
attachLoadBalancers_autoScalingGroupName :: Lens.Lens' AttachLoadBalancers Prelude.Text
attachLoadBalancers_autoScalingGroupName :: (Text -> f Text) -> AttachLoadBalancers -> f AttachLoadBalancers
attachLoadBalancers_autoScalingGroupName = (AttachLoadBalancers -> Text)
-> (AttachLoadBalancers -> Text -> AttachLoadBalancers)
-> Lens AttachLoadBalancers AttachLoadBalancers Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachLoadBalancers' {Text
autoScalingGroupName :: Text
$sel:autoScalingGroupName:AttachLoadBalancers' :: AttachLoadBalancers -> Text
autoScalingGroupName} -> Text
autoScalingGroupName) (\s :: AttachLoadBalancers
s@AttachLoadBalancers' {} Text
a -> AttachLoadBalancers
s {$sel:autoScalingGroupName:AttachLoadBalancers' :: Text
autoScalingGroupName = Text
a} :: AttachLoadBalancers)

-- | The names of the load balancers. You can specify up to 10 load
-- balancers.
attachLoadBalancers_loadBalancerNames :: Lens.Lens' AttachLoadBalancers [Prelude.Text]
attachLoadBalancers_loadBalancerNames :: ([Text] -> f [Text])
-> AttachLoadBalancers -> f AttachLoadBalancers
attachLoadBalancers_loadBalancerNames = (AttachLoadBalancers -> [Text])
-> (AttachLoadBalancers -> [Text] -> AttachLoadBalancers)
-> Lens AttachLoadBalancers AttachLoadBalancers [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachLoadBalancers' {[Text]
loadBalancerNames :: [Text]
$sel:loadBalancerNames:AttachLoadBalancers' :: AttachLoadBalancers -> [Text]
loadBalancerNames} -> [Text]
loadBalancerNames) (\s :: AttachLoadBalancers
s@AttachLoadBalancers' {} [Text]
a -> AttachLoadBalancers
s {$sel:loadBalancerNames:AttachLoadBalancers' :: [Text]
loadBalancerNames = [Text]
a} :: AttachLoadBalancers) (([Text] -> f [Text])
 -> AttachLoadBalancers -> f AttachLoadBalancers)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AttachLoadBalancers
-> f AttachLoadBalancers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest AttachLoadBalancers where
  type
    AWSResponse AttachLoadBalancers =
      AttachLoadBalancersResponse
  request :: AttachLoadBalancers -> Request AttachLoadBalancers
request = Service -> AttachLoadBalancers -> Request AttachLoadBalancers
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy AttachLoadBalancers
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AttachLoadBalancers)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse AttachLoadBalancers))
-> Logger
-> Service
-> Proxy AttachLoadBalancers
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AttachLoadBalancers)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"AttachLoadBalancersResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> AttachLoadBalancersResponse
AttachLoadBalancersResponse'
            (Int -> AttachLoadBalancersResponse)
-> Either String Int -> Either String AttachLoadBalancersResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AttachLoadBalancers

instance Prelude.NFData AttachLoadBalancers

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

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

instance Core.ToQuery AttachLoadBalancers where
  toQuery :: AttachLoadBalancers -> QueryString
toQuery AttachLoadBalancers' {[Text]
Text
loadBalancerNames :: [Text]
autoScalingGroupName :: Text
$sel:loadBalancerNames:AttachLoadBalancers' :: AttachLoadBalancers -> [Text]
$sel:autoScalingGroupName:AttachLoadBalancers' :: AttachLoadBalancers -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"AttachLoadBalancers" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2011-01-01" :: Prelude.ByteString),
        ByteString
"AutoScalingGroupName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
autoScalingGroupName,
        ByteString
"LoadBalancerNames"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" [Text]
loadBalancerNames
      ]

-- | /See:/ 'newAttachLoadBalancersResponse' smart constructor.
data AttachLoadBalancersResponse = AttachLoadBalancersResponse'
  { -- | The response's http status code.
    AttachLoadBalancersResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AttachLoadBalancersResponse -> AttachLoadBalancersResponse -> Bool
(AttachLoadBalancersResponse
 -> AttachLoadBalancersResponse -> Bool)
-> (AttachLoadBalancersResponse
    -> AttachLoadBalancersResponse -> Bool)
-> Eq AttachLoadBalancersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachLoadBalancersResponse -> AttachLoadBalancersResponse -> Bool
$c/= :: AttachLoadBalancersResponse -> AttachLoadBalancersResponse -> Bool
== :: AttachLoadBalancersResponse -> AttachLoadBalancersResponse -> Bool
$c== :: AttachLoadBalancersResponse -> AttachLoadBalancersResponse -> Bool
Prelude.Eq, ReadPrec [AttachLoadBalancersResponse]
ReadPrec AttachLoadBalancersResponse
Int -> ReadS AttachLoadBalancersResponse
ReadS [AttachLoadBalancersResponse]
(Int -> ReadS AttachLoadBalancersResponse)
-> ReadS [AttachLoadBalancersResponse]
-> ReadPrec AttachLoadBalancersResponse
-> ReadPrec [AttachLoadBalancersResponse]
-> Read AttachLoadBalancersResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachLoadBalancersResponse]
$creadListPrec :: ReadPrec [AttachLoadBalancersResponse]
readPrec :: ReadPrec AttachLoadBalancersResponse
$creadPrec :: ReadPrec AttachLoadBalancersResponse
readList :: ReadS [AttachLoadBalancersResponse]
$creadList :: ReadS [AttachLoadBalancersResponse]
readsPrec :: Int -> ReadS AttachLoadBalancersResponse
$creadsPrec :: Int -> ReadS AttachLoadBalancersResponse
Prelude.Read, Int -> AttachLoadBalancersResponse -> ShowS
[AttachLoadBalancersResponse] -> ShowS
AttachLoadBalancersResponse -> String
(Int -> AttachLoadBalancersResponse -> ShowS)
-> (AttachLoadBalancersResponse -> String)
-> ([AttachLoadBalancersResponse] -> ShowS)
-> Show AttachLoadBalancersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachLoadBalancersResponse] -> ShowS
$cshowList :: [AttachLoadBalancersResponse] -> ShowS
show :: AttachLoadBalancersResponse -> String
$cshow :: AttachLoadBalancersResponse -> String
showsPrec :: Int -> AttachLoadBalancersResponse -> ShowS
$cshowsPrec :: Int -> AttachLoadBalancersResponse -> ShowS
Prelude.Show, (forall x.
 AttachLoadBalancersResponse -> Rep AttachLoadBalancersResponse x)
-> (forall x.
    Rep AttachLoadBalancersResponse x -> AttachLoadBalancersResponse)
-> Generic AttachLoadBalancersResponse
forall x.
Rep AttachLoadBalancersResponse x -> AttachLoadBalancersResponse
forall x.
AttachLoadBalancersResponse -> Rep AttachLoadBalancersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AttachLoadBalancersResponse x -> AttachLoadBalancersResponse
$cfrom :: forall x.
AttachLoadBalancersResponse -> Rep AttachLoadBalancersResponse x
Prelude.Generic)

-- |
-- Create a value of 'AttachLoadBalancersResponse' 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:
--
-- 'httpStatus', 'attachLoadBalancersResponse_httpStatus' - The response's http status code.
newAttachLoadBalancersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AttachLoadBalancersResponse
newAttachLoadBalancersResponse :: Int -> AttachLoadBalancersResponse
newAttachLoadBalancersResponse Int
pHttpStatus_ =
  AttachLoadBalancersResponse' :: Int -> AttachLoadBalancersResponse
AttachLoadBalancersResponse'
    { $sel:httpStatus:AttachLoadBalancersResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData AttachLoadBalancersResponse