{-# 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.AttachTrafficSources
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- __Reserved for use with Amazon VPC Lattice, which is in preview and
-- subject to change. Do not use this API for production workloads. This
-- API is also subject to change.__
--
-- Attaches one or more traffic sources to the specified Auto Scaling
-- group.
--
-- To describe the traffic sources for an Auto Scaling group, call the
-- DescribeTrafficSources API. To detach a traffic source from the Auto
-- Scaling group, call the DetachTrafficSources API.
--
-- This operation is additive and does not detach existing traffic sources
-- from the Auto Scaling group.
module Amazonka.AutoScaling.AttachTrafficSources
  ( -- * Creating a Request
    AttachTrafficSources (..),
    newAttachTrafficSources,

    -- * Request Lenses
    attachTrafficSources_autoScalingGroupName,
    attachTrafficSources_trafficSources,

    -- * Destructuring the Response
    AttachTrafficSourcesResponse (..),
    newAttachTrafficSourcesResponse,

    -- * Response Lenses
    attachTrafficSourcesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newAttachTrafficSources' smart constructor.
data AttachTrafficSources = AttachTrafficSources'
  { -- | The name of the Auto Scaling group.
    AttachTrafficSources -> Text
autoScalingGroupName :: Prelude.Text,
    -- | The unique identifiers of one or more traffic sources. You can specify
    -- up to 10 traffic sources.
    --
    -- Currently, you must specify an Amazon Resource Name (ARN) for an
    -- existing VPC Lattice target group. Amazon EC2 Auto Scaling registers the
    -- running instances with the attached target groups. The target groups
    -- receive incoming traffic and route requests to one or more registered
    -- targets.
    AttachTrafficSources -> [TrafficSourceIdentifier]
trafficSources :: [TrafficSourceIdentifier]
  }
  deriving (AttachTrafficSources -> AttachTrafficSources -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachTrafficSources -> AttachTrafficSources -> Bool
$c/= :: AttachTrafficSources -> AttachTrafficSources -> Bool
== :: AttachTrafficSources -> AttachTrafficSources -> Bool
$c== :: AttachTrafficSources -> AttachTrafficSources -> Bool
Prelude.Eq, ReadPrec [AttachTrafficSources]
ReadPrec AttachTrafficSources
Int -> ReadS AttachTrafficSources
ReadS [AttachTrafficSources]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachTrafficSources]
$creadListPrec :: ReadPrec [AttachTrafficSources]
readPrec :: ReadPrec AttachTrafficSources
$creadPrec :: ReadPrec AttachTrafficSources
readList :: ReadS [AttachTrafficSources]
$creadList :: ReadS [AttachTrafficSources]
readsPrec :: Int -> ReadS AttachTrafficSources
$creadsPrec :: Int -> ReadS AttachTrafficSources
Prelude.Read, Int -> AttachTrafficSources -> ShowS
[AttachTrafficSources] -> ShowS
AttachTrafficSources -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachTrafficSources] -> ShowS
$cshowList :: [AttachTrafficSources] -> ShowS
show :: AttachTrafficSources -> String
$cshow :: AttachTrafficSources -> String
showsPrec :: Int -> AttachTrafficSources -> ShowS
$cshowsPrec :: Int -> AttachTrafficSources -> ShowS
Prelude.Show, forall x. Rep AttachTrafficSources x -> AttachTrafficSources
forall x. AttachTrafficSources -> Rep AttachTrafficSources x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachTrafficSources x -> AttachTrafficSources
$cfrom :: forall x. AttachTrafficSources -> Rep AttachTrafficSources x
Prelude.Generic)

-- |
-- Create a value of 'AttachTrafficSources' 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', 'attachTrafficSources_autoScalingGroupName' - The name of the Auto Scaling group.
--
-- 'trafficSources', 'attachTrafficSources_trafficSources' - The unique identifiers of one or more traffic sources. You can specify
-- up to 10 traffic sources.
--
-- Currently, you must specify an Amazon Resource Name (ARN) for an
-- existing VPC Lattice target group. Amazon EC2 Auto Scaling registers the
-- running instances with the attached target groups. The target groups
-- receive incoming traffic and route requests to one or more registered
-- targets.
newAttachTrafficSources ::
  -- | 'autoScalingGroupName'
  Prelude.Text ->
  AttachTrafficSources
newAttachTrafficSources :: Text -> AttachTrafficSources
newAttachTrafficSources Text
pAutoScalingGroupName_ =
  AttachTrafficSources'
    { $sel:autoScalingGroupName:AttachTrafficSources' :: Text
autoScalingGroupName =
        Text
pAutoScalingGroupName_,
      $sel:trafficSources:AttachTrafficSources' :: [TrafficSourceIdentifier]
trafficSources = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | The unique identifiers of one or more traffic sources. You can specify
-- up to 10 traffic sources.
--
-- Currently, you must specify an Amazon Resource Name (ARN) for an
-- existing VPC Lattice target group. Amazon EC2 Auto Scaling registers the
-- running instances with the attached target groups. The target groups
-- receive incoming traffic and route requests to one or more registered
-- targets.
attachTrafficSources_trafficSources :: Lens.Lens' AttachTrafficSources [TrafficSourceIdentifier]
attachTrafficSources_trafficSources :: Lens' AttachTrafficSources [TrafficSourceIdentifier]
attachTrafficSources_trafficSources = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachTrafficSources' {[TrafficSourceIdentifier]
trafficSources :: [TrafficSourceIdentifier]
$sel:trafficSources:AttachTrafficSources' :: AttachTrafficSources -> [TrafficSourceIdentifier]
trafficSources} -> [TrafficSourceIdentifier]
trafficSources) (\s :: AttachTrafficSources
s@AttachTrafficSources' {} [TrafficSourceIdentifier]
a -> AttachTrafficSources
s {$sel:trafficSources:AttachTrafficSources' :: [TrafficSourceIdentifier]
trafficSources = [TrafficSourceIdentifier]
a} :: AttachTrafficSources) 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 AttachTrafficSources where
  type
    AWSResponse AttachTrafficSources =
      AttachTrafficSourcesResponse
  request :: (Service -> Service)
-> AttachTrafficSources -> Request AttachTrafficSources
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 AttachTrafficSources
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AttachTrafficSources)))
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
"AttachTrafficSourcesResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> AttachTrafficSourcesResponse
AttachTrafficSourcesResponse'
            forall (f :: * -> *) a b. Functor 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 AttachTrafficSources where
  hashWithSalt :: Int -> AttachTrafficSources -> Int
hashWithSalt Int
_salt AttachTrafficSources' {[TrafficSourceIdentifier]
Text
trafficSources :: [TrafficSourceIdentifier]
autoScalingGroupName :: Text
$sel:trafficSources:AttachTrafficSources' :: AttachTrafficSources -> [TrafficSourceIdentifier]
$sel:autoScalingGroupName:AttachTrafficSources' :: AttachTrafficSources -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
autoScalingGroupName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [TrafficSourceIdentifier]
trafficSources

instance Prelude.NFData AttachTrafficSources where
  rnf :: AttachTrafficSources -> ()
rnf AttachTrafficSources' {[TrafficSourceIdentifier]
Text
trafficSources :: [TrafficSourceIdentifier]
autoScalingGroupName :: Text
$sel:trafficSources:AttachTrafficSources' :: AttachTrafficSources -> [TrafficSourceIdentifier]
$sel:autoScalingGroupName:AttachTrafficSources' :: AttachTrafficSources -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
autoScalingGroupName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [TrafficSourceIdentifier]
trafficSources

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

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

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

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

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

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

instance Prelude.NFData AttachTrafficSourcesResponse where
  rnf :: AttachTrafficSourcesResponse -> ()
rnf AttachTrafficSourcesResponse' {Int
httpStatus :: Int
$sel:httpStatus:AttachTrafficSourcesResponse' :: AttachTrafficSourcesResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus