{-# 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.CloudFormation.UpdateTerminationProtection
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates termination protection for the specified stack. If a user
-- attempts to delete a stack with termination protection enabled, the
-- operation fails and the stack remains unchanged. For more information,
-- see
-- <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-protect-stacks.html Protecting a Stack From Being Deleted>
-- in the /CloudFormation User Guide/.
--
-- For
-- <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-nested-stacks.html nested stacks>,
-- termination protection is set on the root stack and can\'t be changed
-- directly on the nested stack.
module Amazonka.CloudFormation.UpdateTerminationProtection
  ( -- * Creating a Request
    UpdateTerminationProtection (..),
    newUpdateTerminationProtection,

    -- * Request Lenses
    updateTerminationProtection_enableTerminationProtection,
    updateTerminationProtection_stackName,

    -- * Destructuring the Response
    UpdateTerminationProtectionResponse (..),
    newUpdateTerminationProtectionResponse,

    -- * Response Lenses
    updateTerminationProtectionResponse_stackId,
    updateTerminationProtectionResponse_httpStatus,
  )
where

import Amazonka.CloudFormation.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:/ 'newUpdateTerminationProtection' smart constructor.
data UpdateTerminationProtection = UpdateTerminationProtection'
  { -- | Whether to enable termination protection on the specified stack.
    UpdateTerminationProtection -> Bool
enableTerminationProtection :: Prelude.Bool,
    -- | The name or unique ID of the stack for which you want to set termination
    -- protection.
    UpdateTerminationProtection -> Text
stackName :: Prelude.Text
  }
  deriving (UpdateTerminationProtection -> UpdateTerminationProtection -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateTerminationProtection -> UpdateTerminationProtection -> Bool
$c/= :: UpdateTerminationProtection -> UpdateTerminationProtection -> Bool
== :: UpdateTerminationProtection -> UpdateTerminationProtection -> Bool
$c== :: UpdateTerminationProtection -> UpdateTerminationProtection -> Bool
Prelude.Eq, ReadPrec [UpdateTerminationProtection]
ReadPrec UpdateTerminationProtection
Int -> ReadS UpdateTerminationProtection
ReadS [UpdateTerminationProtection]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateTerminationProtection]
$creadListPrec :: ReadPrec [UpdateTerminationProtection]
readPrec :: ReadPrec UpdateTerminationProtection
$creadPrec :: ReadPrec UpdateTerminationProtection
readList :: ReadS [UpdateTerminationProtection]
$creadList :: ReadS [UpdateTerminationProtection]
readsPrec :: Int -> ReadS UpdateTerminationProtection
$creadsPrec :: Int -> ReadS UpdateTerminationProtection
Prelude.Read, Int -> UpdateTerminationProtection -> ShowS
[UpdateTerminationProtection] -> ShowS
UpdateTerminationProtection -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateTerminationProtection] -> ShowS
$cshowList :: [UpdateTerminationProtection] -> ShowS
show :: UpdateTerminationProtection -> String
$cshow :: UpdateTerminationProtection -> String
showsPrec :: Int -> UpdateTerminationProtection -> ShowS
$cshowsPrec :: Int -> UpdateTerminationProtection -> ShowS
Prelude.Show, forall x.
Rep UpdateTerminationProtection x -> UpdateTerminationProtection
forall x.
UpdateTerminationProtection -> Rep UpdateTerminationProtection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateTerminationProtection x -> UpdateTerminationProtection
$cfrom :: forall x.
UpdateTerminationProtection -> Rep UpdateTerminationProtection x
Prelude.Generic)

-- |
-- Create a value of 'UpdateTerminationProtection' 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:
--
-- 'enableTerminationProtection', 'updateTerminationProtection_enableTerminationProtection' - Whether to enable termination protection on the specified stack.
--
-- 'stackName', 'updateTerminationProtection_stackName' - The name or unique ID of the stack for which you want to set termination
-- protection.
newUpdateTerminationProtection ::
  -- | 'enableTerminationProtection'
  Prelude.Bool ->
  -- | 'stackName'
  Prelude.Text ->
  UpdateTerminationProtection
newUpdateTerminationProtection :: Bool -> Text -> UpdateTerminationProtection
newUpdateTerminationProtection
  Bool
pEnableTerminationProtection_
  Text
pStackName_ =
    UpdateTerminationProtection'
      { $sel:enableTerminationProtection:UpdateTerminationProtection' :: Bool
enableTerminationProtection =
          Bool
pEnableTerminationProtection_,
        $sel:stackName:UpdateTerminationProtection' :: Text
stackName = Text
pStackName_
      }

-- | Whether to enable termination protection on the specified stack.
updateTerminationProtection_enableTerminationProtection :: Lens.Lens' UpdateTerminationProtection Prelude.Bool
updateTerminationProtection_enableTerminationProtection :: Lens' UpdateTerminationProtection Bool
updateTerminationProtection_enableTerminationProtection = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTerminationProtection' {Bool
enableTerminationProtection :: Bool
$sel:enableTerminationProtection:UpdateTerminationProtection' :: UpdateTerminationProtection -> Bool
enableTerminationProtection} -> Bool
enableTerminationProtection) (\s :: UpdateTerminationProtection
s@UpdateTerminationProtection' {} Bool
a -> UpdateTerminationProtection
s {$sel:enableTerminationProtection:UpdateTerminationProtection' :: Bool
enableTerminationProtection = Bool
a} :: UpdateTerminationProtection)

-- | The name or unique ID of the stack for which you want to set termination
-- protection.
updateTerminationProtection_stackName :: Lens.Lens' UpdateTerminationProtection Prelude.Text
updateTerminationProtection_stackName :: Lens' UpdateTerminationProtection Text
updateTerminationProtection_stackName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTerminationProtection' {Text
stackName :: Text
$sel:stackName:UpdateTerminationProtection' :: UpdateTerminationProtection -> Text
stackName} -> Text
stackName) (\s :: UpdateTerminationProtection
s@UpdateTerminationProtection' {} Text
a -> UpdateTerminationProtection
s {$sel:stackName:UpdateTerminationProtection' :: Text
stackName = Text
a} :: UpdateTerminationProtection)

instance Core.AWSRequest UpdateTerminationProtection where
  type
    AWSResponse UpdateTerminationProtection =
      UpdateTerminationProtectionResponse
  request :: (Service -> Service)
-> UpdateTerminationProtection
-> Request UpdateTerminationProtection
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 UpdateTerminationProtection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateTerminationProtection)))
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
"UpdateTerminationProtectionResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Int -> UpdateTerminationProtectionResponse
UpdateTerminationProtectionResponse'
            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
"StackId")
            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 UpdateTerminationProtection where
  hashWithSalt :: Int -> UpdateTerminationProtection -> Int
hashWithSalt Int
_salt UpdateTerminationProtection' {Bool
Text
stackName :: Text
enableTerminationProtection :: Bool
$sel:stackName:UpdateTerminationProtection' :: UpdateTerminationProtection -> Text
$sel:enableTerminationProtection:UpdateTerminationProtection' :: UpdateTerminationProtection -> Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enableTerminationProtection
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
stackName

instance Prelude.NFData UpdateTerminationProtection where
  rnf :: UpdateTerminationProtection -> ()
rnf UpdateTerminationProtection' {Bool
Text
stackName :: Text
enableTerminationProtection :: Bool
$sel:stackName:UpdateTerminationProtection' :: UpdateTerminationProtection -> Text
$sel:enableTerminationProtection:UpdateTerminationProtection' :: UpdateTerminationProtection -> Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Bool
enableTerminationProtection
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
stackName

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

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

instance Data.ToQuery UpdateTerminationProtection where
  toQuery :: UpdateTerminationProtection -> QueryString
toQuery UpdateTerminationProtection' {Bool
Text
stackName :: Text
enableTerminationProtection :: Bool
$sel:stackName:UpdateTerminationProtection' :: UpdateTerminationProtection -> Text
$sel:enableTerminationProtection:UpdateTerminationProtection' :: UpdateTerminationProtection -> Bool
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: ( ByteString
"UpdateTerminationProtection" ::
                      Prelude.ByteString
                  ),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-05-15" :: Prelude.ByteString),
        ByteString
"EnableTerminationProtection"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Bool
enableTerminationProtection,
        ByteString
"StackName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
stackName
      ]

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

-- |
-- Create a value of 'UpdateTerminationProtectionResponse' 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:
--
-- 'stackId', 'updateTerminationProtectionResponse_stackId' - The unique ID of the stack.
--
-- 'httpStatus', 'updateTerminationProtectionResponse_httpStatus' - The response's http status code.
newUpdateTerminationProtectionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateTerminationProtectionResponse
newUpdateTerminationProtectionResponse :: Int -> UpdateTerminationProtectionResponse
newUpdateTerminationProtectionResponse Int
pHttpStatus_ =
  UpdateTerminationProtectionResponse'
    { $sel:stackId:UpdateTerminationProtectionResponse' :: Maybe Text
stackId =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateTerminationProtectionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The unique ID of the stack.
updateTerminationProtectionResponse_stackId :: Lens.Lens' UpdateTerminationProtectionResponse (Prelude.Maybe Prelude.Text)
updateTerminationProtectionResponse_stackId :: Lens' UpdateTerminationProtectionResponse (Maybe Text)
updateTerminationProtectionResponse_stackId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateTerminationProtectionResponse' {Maybe Text
stackId :: Maybe Text
$sel:stackId:UpdateTerminationProtectionResponse' :: UpdateTerminationProtectionResponse -> Maybe Text
stackId} -> Maybe Text
stackId) (\s :: UpdateTerminationProtectionResponse
s@UpdateTerminationProtectionResponse' {} Maybe Text
a -> UpdateTerminationProtectionResponse
s {$sel:stackId:UpdateTerminationProtectionResponse' :: Maybe Text
stackId = Maybe Text
a} :: UpdateTerminationProtectionResponse)

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

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