{-# 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-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)
--
-- 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 cannot 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.Lens as Lens
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
(UpdateTerminationProtection
 -> UpdateTerminationProtection -> Bool)
-> (UpdateTerminationProtection
    -> UpdateTerminationProtection -> Bool)
-> Eq UpdateTerminationProtection
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]
(Int -> ReadS UpdateTerminationProtection)
-> ReadS [UpdateTerminationProtection]
-> ReadPrec UpdateTerminationProtection
-> ReadPrec [UpdateTerminationProtection]
-> Read 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
(Int -> UpdateTerminationProtection -> ShowS)
-> (UpdateTerminationProtection -> String)
-> ([UpdateTerminationProtection] -> ShowS)
-> Show UpdateTerminationProtection
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.
 UpdateTerminationProtection -> Rep UpdateTerminationProtection x)
-> (forall x.
    Rep UpdateTerminationProtection x -> UpdateTerminationProtection)
-> Generic UpdateTerminationProtection
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' :: Bool -> Text -> UpdateTerminationProtection
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 :: (Bool -> f Bool)
-> UpdateTerminationProtection -> f UpdateTerminationProtection
updateTerminationProtection_enableTerminationProtection = (UpdateTerminationProtection -> Bool)
-> (UpdateTerminationProtection
    -> Bool -> UpdateTerminationProtection)
-> Lens
     UpdateTerminationProtection UpdateTerminationProtection Bool Bool
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 :: (Text -> f Text)
-> UpdateTerminationProtection -> f UpdateTerminationProtection
updateTerminationProtection_stackName = (UpdateTerminationProtection -> Text)
-> (UpdateTerminationProtection
    -> Text -> UpdateTerminationProtection)
-> Lens
     UpdateTerminationProtection UpdateTerminationProtection Text Text
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 :: UpdateTerminationProtection -> Request UpdateTerminationProtection
request = Service
-> UpdateTerminationProtection
-> Request UpdateTerminationProtection
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateTerminationProtection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateTerminationProtection)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse UpdateTerminationProtection))
-> Logger
-> Service
-> Proxy UpdateTerminationProtection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateTerminationProtection)))
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
"UpdateTerminationProtectionResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Int -> UpdateTerminationProtectionResponse
UpdateTerminationProtectionResponse'
            (Maybe Text -> Int -> UpdateTerminationProtectionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> UpdateTerminationProtectionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"StackId")
            Either String (Int -> UpdateTerminationProtectionResponse)
-> Either String Int
-> Either String UpdateTerminationProtectionResponse
forall (f :: * -> *) a b. Applicative f => 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 UpdateTerminationProtection

instance Prelude.NFData UpdateTerminationProtection

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

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

instance Core.ToQuery UpdateTerminationProtection where
  toQuery :: UpdateTerminationProtection -> QueryString
toQuery UpdateTerminationProtection' {Bool
Text
stackName :: Text
enableTerminationProtection :: Bool
$sel:stackName:UpdateTerminationProtection' :: UpdateTerminationProtection -> Text
$sel:enableTerminationProtection:UpdateTerminationProtection' :: UpdateTerminationProtection -> Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ( ByteString
"UpdateTerminationProtection" ::
                      Prelude.ByteString
                  ),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-05-15" :: Prelude.ByteString),
        ByteString
"EnableTerminationProtection"
          ByteString -> Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Bool
enableTerminationProtection,
        ByteString
"StackName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: 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
(UpdateTerminationProtectionResponse
 -> UpdateTerminationProtectionResponse -> Bool)
-> (UpdateTerminationProtectionResponse
    -> UpdateTerminationProtectionResponse -> Bool)
-> Eq UpdateTerminationProtectionResponse
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]
(Int -> ReadS UpdateTerminationProtectionResponse)
-> ReadS [UpdateTerminationProtectionResponse]
-> ReadPrec UpdateTerminationProtectionResponse
-> ReadPrec [UpdateTerminationProtectionResponse]
-> Read 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
(Int -> UpdateTerminationProtectionResponse -> ShowS)
-> (UpdateTerminationProtectionResponse -> String)
-> ([UpdateTerminationProtectionResponse] -> ShowS)
-> Show UpdateTerminationProtectionResponse
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.
 UpdateTerminationProtectionResponse
 -> Rep UpdateTerminationProtectionResponse x)
-> (forall x.
    Rep UpdateTerminationProtectionResponse x
    -> UpdateTerminationProtectionResponse)
-> Generic UpdateTerminationProtectionResponse
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' :: Maybe Text -> Int -> UpdateTerminationProtectionResponse
UpdateTerminationProtectionResponse'
    { $sel:stackId:UpdateTerminationProtectionResponse' :: Maybe Text
stackId =
        Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> UpdateTerminationProtectionResponse
-> f UpdateTerminationProtectionResponse
updateTerminationProtectionResponse_stackId = (UpdateTerminationProtectionResponse -> Maybe Text)
-> (UpdateTerminationProtectionResponse
    -> Maybe Text -> UpdateTerminationProtectionResponse)
-> Lens
     UpdateTerminationProtectionResponse
     UpdateTerminationProtectionResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> UpdateTerminationProtectionResponse
-> f UpdateTerminationProtectionResponse
updateTerminationProtectionResponse_httpStatus = (UpdateTerminationProtectionResponse -> Int)
-> (UpdateTerminationProtectionResponse
    -> Int -> UpdateTerminationProtectionResponse)
-> Lens
     UpdateTerminationProtectionResponse
     UpdateTerminationProtectionResponse
     Int
     Int
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