{-# 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.Lightsail.AttachInstancesToLoadBalancer
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Attaches one or more Lightsail instances to a load balancer.
--
-- After some time, the instances are attached to the load balancer and the
-- health check status is available.
--
-- The @attach instances to load balancer@ operation supports tag-based
-- access control via resource tags applied to the resource identified by
-- @load balancer name@. For more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Lightsail Developer Guide>.
module Amazonka.Lightsail.AttachInstancesToLoadBalancer
  ( -- * Creating a Request
    AttachInstancesToLoadBalancer (..),
    newAttachInstancesToLoadBalancer,

    -- * Request Lenses
    attachInstancesToLoadBalancer_loadBalancerName,
    attachInstancesToLoadBalancer_instanceNames,

    -- * Destructuring the Response
    AttachInstancesToLoadBalancerResponse (..),
    newAttachInstancesToLoadBalancerResponse,

    -- * Response Lenses
    attachInstancesToLoadBalancerResponse_operations,
    attachInstancesToLoadBalancerResponse_httpStatus,
  )
where

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

-- | /See:/ 'newAttachInstancesToLoadBalancer' smart constructor.
data AttachInstancesToLoadBalancer = AttachInstancesToLoadBalancer'
  { -- | The name of the load balancer.
    AttachInstancesToLoadBalancer -> Text
loadBalancerName :: Prelude.Text,
    -- | An array of strings representing the instance name(s) you want to attach
    -- to your load balancer.
    --
    -- An instance must be @running@ before you can attach it to your load
    -- balancer.
    --
    -- There are no additional limits on the number of instances you can attach
    -- to your load balancer, aside from the limit of Lightsail instances you
    -- can create in your account (20).
    AttachInstancesToLoadBalancer -> [Text]
instanceNames :: [Prelude.Text]
  }
  deriving (AttachInstancesToLoadBalancer
-> AttachInstancesToLoadBalancer -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachInstancesToLoadBalancer
-> AttachInstancesToLoadBalancer -> Bool
$c/= :: AttachInstancesToLoadBalancer
-> AttachInstancesToLoadBalancer -> Bool
== :: AttachInstancesToLoadBalancer
-> AttachInstancesToLoadBalancer -> Bool
$c== :: AttachInstancesToLoadBalancer
-> AttachInstancesToLoadBalancer -> Bool
Prelude.Eq, ReadPrec [AttachInstancesToLoadBalancer]
ReadPrec AttachInstancesToLoadBalancer
Int -> ReadS AttachInstancesToLoadBalancer
ReadS [AttachInstancesToLoadBalancer]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachInstancesToLoadBalancer]
$creadListPrec :: ReadPrec [AttachInstancesToLoadBalancer]
readPrec :: ReadPrec AttachInstancesToLoadBalancer
$creadPrec :: ReadPrec AttachInstancesToLoadBalancer
readList :: ReadS [AttachInstancesToLoadBalancer]
$creadList :: ReadS [AttachInstancesToLoadBalancer]
readsPrec :: Int -> ReadS AttachInstancesToLoadBalancer
$creadsPrec :: Int -> ReadS AttachInstancesToLoadBalancer
Prelude.Read, Int -> AttachInstancesToLoadBalancer -> ShowS
[AttachInstancesToLoadBalancer] -> ShowS
AttachInstancesToLoadBalancer -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachInstancesToLoadBalancer] -> ShowS
$cshowList :: [AttachInstancesToLoadBalancer] -> ShowS
show :: AttachInstancesToLoadBalancer -> String
$cshow :: AttachInstancesToLoadBalancer -> String
showsPrec :: Int -> AttachInstancesToLoadBalancer -> ShowS
$cshowsPrec :: Int -> AttachInstancesToLoadBalancer -> ShowS
Prelude.Show, forall x.
Rep AttachInstancesToLoadBalancer x
-> AttachInstancesToLoadBalancer
forall x.
AttachInstancesToLoadBalancer
-> Rep AttachInstancesToLoadBalancer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AttachInstancesToLoadBalancer x
-> AttachInstancesToLoadBalancer
$cfrom :: forall x.
AttachInstancesToLoadBalancer
-> Rep AttachInstancesToLoadBalancer x
Prelude.Generic)

-- |
-- Create a value of 'AttachInstancesToLoadBalancer' 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', 'attachInstancesToLoadBalancer_loadBalancerName' - The name of the load balancer.
--
-- 'instanceNames', 'attachInstancesToLoadBalancer_instanceNames' - An array of strings representing the instance name(s) you want to attach
-- to your load balancer.
--
-- An instance must be @running@ before you can attach it to your load
-- balancer.
--
-- There are no additional limits on the number of instances you can attach
-- to your load balancer, aside from the limit of Lightsail instances you
-- can create in your account (20).
newAttachInstancesToLoadBalancer ::
  -- | 'loadBalancerName'
  Prelude.Text ->
  AttachInstancesToLoadBalancer
newAttachInstancesToLoadBalancer :: Text -> AttachInstancesToLoadBalancer
newAttachInstancesToLoadBalancer Text
pLoadBalancerName_ =
  AttachInstancesToLoadBalancer'
    { $sel:loadBalancerName:AttachInstancesToLoadBalancer' :: Text
loadBalancerName =
        Text
pLoadBalancerName_,
      $sel:instanceNames:AttachInstancesToLoadBalancer' :: [Text]
instanceNames = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | An array of strings representing the instance name(s) you want to attach
-- to your load balancer.
--
-- An instance must be @running@ before you can attach it to your load
-- balancer.
--
-- There are no additional limits on the number of instances you can attach
-- to your load balancer, aside from the limit of Lightsail instances you
-- can create in your account (20).
attachInstancesToLoadBalancer_instanceNames :: Lens.Lens' AttachInstancesToLoadBalancer [Prelude.Text]
attachInstancesToLoadBalancer_instanceNames :: Lens' AttachInstancesToLoadBalancer [Text]
attachInstancesToLoadBalancer_instanceNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachInstancesToLoadBalancer' {[Text]
instanceNames :: [Text]
$sel:instanceNames:AttachInstancesToLoadBalancer' :: AttachInstancesToLoadBalancer -> [Text]
instanceNames} -> [Text]
instanceNames) (\s :: AttachInstancesToLoadBalancer
s@AttachInstancesToLoadBalancer' {} [Text]
a -> AttachInstancesToLoadBalancer
s {$sel:instanceNames:AttachInstancesToLoadBalancer' :: [Text]
instanceNames = [Text]
a} :: AttachInstancesToLoadBalancer) 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
    AttachInstancesToLoadBalancer
  where
  type
    AWSResponse AttachInstancesToLoadBalancer =
      AttachInstancesToLoadBalancerResponse
  request :: (Service -> Service)
-> AttachInstancesToLoadBalancer
-> Request AttachInstancesToLoadBalancer
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AttachInstancesToLoadBalancer
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AttachInstancesToLoadBalancer)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Operation] -> Int -> AttachInstancesToLoadBalancerResponse
AttachInstancesToLoadBalancerResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"operations" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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
    AttachInstancesToLoadBalancer
  where
  hashWithSalt :: Int -> AttachInstancesToLoadBalancer -> Int
hashWithSalt Int
_salt AttachInstancesToLoadBalancer' {[Text]
Text
instanceNames :: [Text]
loadBalancerName :: Text
$sel:instanceNames:AttachInstancesToLoadBalancer' :: AttachInstancesToLoadBalancer -> [Text]
$sel:loadBalancerName:AttachInstancesToLoadBalancer' :: AttachInstancesToLoadBalancer -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
loadBalancerName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
instanceNames

instance Prelude.NFData AttachInstancesToLoadBalancer where
  rnf :: AttachInstancesToLoadBalancer -> ()
rnf AttachInstancesToLoadBalancer' {[Text]
Text
instanceNames :: [Text]
loadBalancerName :: Text
$sel:instanceNames:AttachInstancesToLoadBalancer' :: AttachInstancesToLoadBalancer -> [Text]
$sel:loadBalancerName:AttachInstancesToLoadBalancer' :: AttachInstancesToLoadBalancer -> 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]
instanceNames

instance Data.ToHeaders AttachInstancesToLoadBalancer where
  toHeaders :: AttachInstancesToLoadBalancer -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"Lightsail_20161128.AttachInstancesToLoadBalancer" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON AttachInstancesToLoadBalancer where
  toJSON :: AttachInstancesToLoadBalancer -> Value
toJSON AttachInstancesToLoadBalancer' {[Text]
Text
instanceNames :: [Text]
loadBalancerName :: Text
$sel:instanceNames:AttachInstancesToLoadBalancer' :: AttachInstancesToLoadBalancer -> [Text]
$sel:loadBalancerName:AttachInstancesToLoadBalancer' :: AttachInstancesToLoadBalancer -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"loadBalancerName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
loadBalancerName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"instanceNames" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
instanceNames)
          ]
      )

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

instance Data.ToQuery AttachInstancesToLoadBalancer where
  toQuery :: AttachInstancesToLoadBalancer -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newAttachInstancesToLoadBalancerResponse' smart constructor.
data AttachInstancesToLoadBalancerResponse = AttachInstancesToLoadBalancerResponse'
  { -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    AttachInstancesToLoadBalancerResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    AttachInstancesToLoadBalancerResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AttachInstancesToLoadBalancerResponse
-> AttachInstancesToLoadBalancerResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachInstancesToLoadBalancerResponse
-> AttachInstancesToLoadBalancerResponse -> Bool
$c/= :: AttachInstancesToLoadBalancerResponse
-> AttachInstancesToLoadBalancerResponse -> Bool
== :: AttachInstancesToLoadBalancerResponse
-> AttachInstancesToLoadBalancerResponse -> Bool
$c== :: AttachInstancesToLoadBalancerResponse
-> AttachInstancesToLoadBalancerResponse -> Bool
Prelude.Eq, ReadPrec [AttachInstancesToLoadBalancerResponse]
ReadPrec AttachInstancesToLoadBalancerResponse
Int -> ReadS AttachInstancesToLoadBalancerResponse
ReadS [AttachInstancesToLoadBalancerResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachInstancesToLoadBalancerResponse]
$creadListPrec :: ReadPrec [AttachInstancesToLoadBalancerResponse]
readPrec :: ReadPrec AttachInstancesToLoadBalancerResponse
$creadPrec :: ReadPrec AttachInstancesToLoadBalancerResponse
readList :: ReadS [AttachInstancesToLoadBalancerResponse]
$creadList :: ReadS [AttachInstancesToLoadBalancerResponse]
readsPrec :: Int -> ReadS AttachInstancesToLoadBalancerResponse
$creadsPrec :: Int -> ReadS AttachInstancesToLoadBalancerResponse
Prelude.Read, Int -> AttachInstancesToLoadBalancerResponse -> ShowS
[AttachInstancesToLoadBalancerResponse] -> ShowS
AttachInstancesToLoadBalancerResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachInstancesToLoadBalancerResponse] -> ShowS
$cshowList :: [AttachInstancesToLoadBalancerResponse] -> ShowS
show :: AttachInstancesToLoadBalancerResponse -> String
$cshow :: AttachInstancesToLoadBalancerResponse -> String
showsPrec :: Int -> AttachInstancesToLoadBalancerResponse -> ShowS
$cshowsPrec :: Int -> AttachInstancesToLoadBalancerResponse -> ShowS
Prelude.Show, forall x.
Rep AttachInstancesToLoadBalancerResponse x
-> AttachInstancesToLoadBalancerResponse
forall x.
AttachInstancesToLoadBalancerResponse
-> Rep AttachInstancesToLoadBalancerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AttachInstancesToLoadBalancerResponse x
-> AttachInstancesToLoadBalancerResponse
$cfrom :: forall x.
AttachInstancesToLoadBalancerResponse
-> Rep AttachInstancesToLoadBalancerResponse x
Prelude.Generic)

-- |
-- Create a value of 'AttachInstancesToLoadBalancerResponse' 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:
--
-- 'operations', 'attachInstancesToLoadBalancerResponse_operations' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'attachInstancesToLoadBalancerResponse_httpStatus' - The response's http status code.
newAttachInstancesToLoadBalancerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AttachInstancesToLoadBalancerResponse
newAttachInstancesToLoadBalancerResponse :: Int -> AttachInstancesToLoadBalancerResponse
newAttachInstancesToLoadBalancerResponse Int
pHttpStatus_ =
  AttachInstancesToLoadBalancerResponse'
    { $sel:operations:AttachInstancesToLoadBalancerResponse' :: Maybe [Operation]
operations =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AttachInstancesToLoadBalancerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
attachInstancesToLoadBalancerResponse_operations :: Lens.Lens' AttachInstancesToLoadBalancerResponse (Prelude.Maybe [Operation])
attachInstancesToLoadBalancerResponse_operations :: Lens' AttachInstancesToLoadBalancerResponse (Maybe [Operation])
attachInstancesToLoadBalancerResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachInstancesToLoadBalancerResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:AttachInstancesToLoadBalancerResponse' :: AttachInstancesToLoadBalancerResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: AttachInstancesToLoadBalancerResponse
s@AttachInstancesToLoadBalancerResponse' {} Maybe [Operation]
a -> AttachInstancesToLoadBalancerResponse
s {$sel:operations:AttachInstancesToLoadBalancerResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: AttachInstancesToLoadBalancerResponse) 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.
attachInstancesToLoadBalancerResponse_httpStatus :: Lens.Lens' AttachInstancesToLoadBalancerResponse Prelude.Int
attachInstancesToLoadBalancerResponse_httpStatus :: Lens' AttachInstancesToLoadBalancerResponse Int
attachInstancesToLoadBalancerResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachInstancesToLoadBalancerResponse' {Int
httpStatus :: Int
$sel:httpStatus:AttachInstancesToLoadBalancerResponse' :: AttachInstancesToLoadBalancerResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AttachInstancesToLoadBalancerResponse
s@AttachInstancesToLoadBalancerResponse' {} Int
a -> AttachInstancesToLoadBalancerResponse
s {$sel:httpStatus:AttachInstancesToLoadBalancerResponse' :: Int
httpStatus = Int
a} :: AttachInstancesToLoadBalancerResponse)

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