{-# 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.OpsWorks.DeregisterInstance
-- 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)
--
-- Deregister a registered Amazon EC2 or on-premises instance. This action
-- removes the instance from the stack and returns it to your control. This
-- action cannot be used with instances that were created with AWS OpsWorks
-- Stacks.
--
-- __Required Permissions__: To use this action, an IAM user must have a
-- Manage permissions level for the stack or an attached policy that
-- explicitly grants permissions. For more information on user permissions,
-- see
-- <https://docs.aws.amazon.com/opsworks/latest/userguide/opsworks-security-users.html Managing User Permissions>.
module Amazonka.OpsWorks.DeregisterInstance
  ( -- * Creating a Request
    DeregisterInstance (..),
    newDeregisterInstance,

    -- * Request Lenses
    deregisterInstance_instanceId,

    -- * Destructuring the Response
    DeregisterInstanceResponse (..),
    newDeregisterInstanceResponse,
  )
where

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

-- | /See:/ 'newDeregisterInstance' smart constructor.
data DeregisterInstance = DeregisterInstance'
  { -- | The instance ID.
    DeregisterInstance -> Text
instanceId :: Prelude.Text
  }
  deriving (DeregisterInstance -> DeregisterInstance -> Bool
(DeregisterInstance -> DeregisterInstance -> Bool)
-> (DeregisterInstance -> DeregisterInstance -> Bool)
-> Eq DeregisterInstance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeregisterInstance -> DeregisterInstance -> Bool
$c/= :: DeregisterInstance -> DeregisterInstance -> Bool
== :: DeregisterInstance -> DeregisterInstance -> Bool
$c== :: DeregisterInstance -> DeregisterInstance -> Bool
Prelude.Eq, ReadPrec [DeregisterInstance]
ReadPrec DeregisterInstance
Int -> ReadS DeregisterInstance
ReadS [DeregisterInstance]
(Int -> ReadS DeregisterInstance)
-> ReadS [DeregisterInstance]
-> ReadPrec DeregisterInstance
-> ReadPrec [DeregisterInstance]
-> Read DeregisterInstance
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeregisterInstance]
$creadListPrec :: ReadPrec [DeregisterInstance]
readPrec :: ReadPrec DeregisterInstance
$creadPrec :: ReadPrec DeregisterInstance
readList :: ReadS [DeregisterInstance]
$creadList :: ReadS [DeregisterInstance]
readsPrec :: Int -> ReadS DeregisterInstance
$creadsPrec :: Int -> ReadS DeregisterInstance
Prelude.Read, Int -> DeregisterInstance -> ShowS
[DeregisterInstance] -> ShowS
DeregisterInstance -> String
(Int -> DeregisterInstance -> ShowS)
-> (DeregisterInstance -> String)
-> ([DeregisterInstance] -> ShowS)
-> Show DeregisterInstance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeregisterInstance] -> ShowS
$cshowList :: [DeregisterInstance] -> ShowS
show :: DeregisterInstance -> String
$cshow :: DeregisterInstance -> String
showsPrec :: Int -> DeregisterInstance -> ShowS
$cshowsPrec :: Int -> DeregisterInstance -> ShowS
Prelude.Show, (forall x. DeregisterInstance -> Rep DeregisterInstance x)
-> (forall x. Rep DeregisterInstance x -> DeregisterInstance)
-> Generic DeregisterInstance
forall x. Rep DeregisterInstance x -> DeregisterInstance
forall x. DeregisterInstance -> Rep DeregisterInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeregisterInstance x -> DeregisterInstance
$cfrom :: forall x. DeregisterInstance -> Rep DeregisterInstance x
Prelude.Generic)

-- |
-- Create a value of 'DeregisterInstance' 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:
--
-- 'instanceId', 'deregisterInstance_instanceId' - The instance ID.
newDeregisterInstance ::
  -- | 'instanceId'
  Prelude.Text ->
  DeregisterInstance
newDeregisterInstance :: Text -> DeregisterInstance
newDeregisterInstance Text
pInstanceId_ =
  DeregisterInstance' :: Text -> DeregisterInstance
DeregisterInstance' {$sel:instanceId:DeregisterInstance' :: Text
instanceId = Text
pInstanceId_}

-- | The instance ID.
deregisterInstance_instanceId :: Lens.Lens' DeregisterInstance Prelude.Text
deregisterInstance_instanceId :: (Text -> f Text) -> DeregisterInstance -> f DeregisterInstance
deregisterInstance_instanceId = (DeregisterInstance -> Text)
-> (DeregisterInstance -> Text -> DeregisterInstance)
-> Lens DeregisterInstance DeregisterInstance Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeregisterInstance' {Text
instanceId :: Text
$sel:instanceId:DeregisterInstance' :: DeregisterInstance -> Text
instanceId} -> Text
instanceId) (\s :: DeregisterInstance
s@DeregisterInstance' {} Text
a -> DeregisterInstance
s {$sel:instanceId:DeregisterInstance' :: Text
instanceId = Text
a} :: DeregisterInstance)

instance Core.AWSRequest DeregisterInstance where
  type
    AWSResponse DeregisterInstance =
      DeregisterInstanceResponse
  request :: DeregisterInstance -> Request DeregisterInstance
request = Service -> DeregisterInstance -> Request DeregisterInstance
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeregisterInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeregisterInstance)))
response =
    AWSResponse DeregisterInstance
-> Logger
-> Service
-> Proxy DeregisterInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeregisterInstance)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse DeregisterInstance
DeregisterInstanceResponse
DeregisterInstanceResponse'

instance Prelude.Hashable DeregisterInstance

instance Prelude.NFData DeregisterInstance

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

instance Core.ToJSON DeregisterInstance where
  toJSON :: DeregisterInstance -> Value
toJSON DeregisterInstance' {Text
instanceId :: Text
$sel:instanceId:DeregisterInstance' :: DeregisterInstance -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceId)]
      )

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

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

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

-- |
-- Create a value of 'DeregisterInstanceResponse' 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.
newDeregisterInstanceResponse ::
  DeregisterInstanceResponse
newDeregisterInstanceResponse :: DeregisterInstanceResponse
newDeregisterInstanceResponse =
  DeregisterInstanceResponse
DeregisterInstanceResponse'

instance Prelude.NFData DeregisterInstanceResponse