{-# 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.RollbackStack
-- 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)
--
-- When specifying @RollbackStack@, you preserve the state of previously
-- provisioned resources when an operation fails. You can check the status
-- of the stack through the DescribeStacks API.
--
-- Rolls back the specified stack to the last known stable state from
-- @CREATE_FAILED@ or @UPDATE_FAILED@ stack statuses.
--
-- This operation will delete a stack if it doesn\'t contain a last known
-- stable state. A last known stable state includes any status in a
-- @*_COMPLETE@. This includes the following stack statuses.
--
-- -   @CREATE_COMPLETE@
--
-- -   @UPDATE_COMPLETE@
--
-- -   @UPDATE_ROLLBACK_COMPLETE@
--
-- -   @IMPORT_COMPLETE@
--
-- -   @IMPORT_ROLLBACK_COMPLETE@
module Amazonka.CloudFormation.RollbackStack
  ( -- * Creating a Request
    RollbackStack (..),
    newRollbackStack,

    -- * Request Lenses
    rollbackStack_clientRequestToken,
    rollbackStack_roleARN,
    rollbackStack_stackName,

    -- * Destructuring the Response
    RollbackStackResponse (..),
    newRollbackStackResponse,

    -- * Response Lenses
    rollbackStackResponse_stackId,
    rollbackStackResponse_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:/ 'newRollbackStack' smart constructor.
data RollbackStack = RollbackStack'
  { -- | A unique identifier for this @RollbackStack@ request.
    RollbackStack -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of an Identity and Access Management role
    -- that CloudFormation assumes to rollback the stack.
    RollbackStack -> Maybe Text
roleARN :: Prelude.Maybe Prelude.Text,
    -- | The name that is associated with the stack.
    RollbackStack -> Text
stackName :: Prelude.Text
  }
  deriving (RollbackStack -> RollbackStack -> Bool
(RollbackStack -> RollbackStack -> Bool)
-> (RollbackStack -> RollbackStack -> Bool) -> Eq RollbackStack
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RollbackStack -> RollbackStack -> Bool
$c/= :: RollbackStack -> RollbackStack -> Bool
== :: RollbackStack -> RollbackStack -> Bool
$c== :: RollbackStack -> RollbackStack -> Bool
Prelude.Eq, ReadPrec [RollbackStack]
ReadPrec RollbackStack
Int -> ReadS RollbackStack
ReadS [RollbackStack]
(Int -> ReadS RollbackStack)
-> ReadS [RollbackStack]
-> ReadPrec RollbackStack
-> ReadPrec [RollbackStack]
-> Read RollbackStack
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RollbackStack]
$creadListPrec :: ReadPrec [RollbackStack]
readPrec :: ReadPrec RollbackStack
$creadPrec :: ReadPrec RollbackStack
readList :: ReadS [RollbackStack]
$creadList :: ReadS [RollbackStack]
readsPrec :: Int -> ReadS RollbackStack
$creadsPrec :: Int -> ReadS RollbackStack
Prelude.Read, Int -> RollbackStack -> ShowS
[RollbackStack] -> ShowS
RollbackStack -> String
(Int -> RollbackStack -> ShowS)
-> (RollbackStack -> String)
-> ([RollbackStack] -> ShowS)
-> Show RollbackStack
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RollbackStack] -> ShowS
$cshowList :: [RollbackStack] -> ShowS
show :: RollbackStack -> String
$cshow :: RollbackStack -> String
showsPrec :: Int -> RollbackStack -> ShowS
$cshowsPrec :: Int -> RollbackStack -> ShowS
Prelude.Show, (forall x. RollbackStack -> Rep RollbackStack x)
-> (forall x. Rep RollbackStack x -> RollbackStack)
-> Generic RollbackStack
forall x. Rep RollbackStack x -> RollbackStack
forall x. RollbackStack -> Rep RollbackStack x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RollbackStack x -> RollbackStack
$cfrom :: forall x. RollbackStack -> Rep RollbackStack x
Prelude.Generic)

-- |
-- Create a value of 'RollbackStack' 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:
--
-- 'clientRequestToken', 'rollbackStack_clientRequestToken' - A unique identifier for this @RollbackStack@ request.
--
-- 'roleARN', 'rollbackStack_roleARN' - The Amazon Resource Name (ARN) of an Identity and Access Management role
-- that CloudFormation assumes to rollback the stack.
--
-- 'stackName', 'rollbackStack_stackName' - The name that is associated with the stack.
newRollbackStack ::
  -- | 'stackName'
  Prelude.Text ->
  RollbackStack
newRollbackStack :: Text -> RollbackStack
newRollbackStack Text
pStackName_ =
  RollbackStack' :: Maybe Text -> Maybe Text -> Text -> RollbackStack
RollbackStack'
    { $sel:clientRequestToken:RollbackStack' :: Maybe Text
clientRequestToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:roleARN:RollbackStack' :: Maybe Text
roleARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stackName:RollbackStack' :: Text
stackName = Text
pStackName_
    }

-- | A unique identifier for this @RollbackStack@ request.
rollbackStack_clientRequestToken :: Lens.Lens' RollbackStack (Prelude.Maybe Prelude.Text)
rollbackStack_clientRequestToken :: (Maybe Text -> f (Maybe Text)) -> RollbackStack -> f RollbackStack
rollbackStack_clientRequestToken = (RollbackStack -> Maybe Text)
-> (RollbackStack -> Maybe Text -> RollbackStack)
-> Lens RollbackStack RollbackStack (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackStack' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:RollbackStack' :: RollbackStack -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: RollbackStack
s@RollbackStack' {} Maybe Text
a -> RollbackStack
s {$sel:clientRequestToken:RollbackStack' :: Maybe Text
clientRequestToken = Maybe Text
a} :: RollbackStack)

-- | The Amazon Resource Name (ARN) of an Identity and Access Management role
-- that CloudFormation assumes to rollback the stack.
rollbackStack_roleARN :: Lens.Lens' RollbackStack (Prelude.Maybe Prelude.Text)
rollbackStack_roleARN :: (Maybe Text -> f (Maybe Text)) -> RollbackStack -> f RollbackStack
rollbackStack_roleARN = (RollbackStack -> Maybe Text)
-> (RollbackStack -> Maybe Text -> RollbackStack)
-> Lens RollbackStack RollbackStack (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackStack' {Maybe Text
roleARN :: Maybe Text
$sel:roleARN:RollbackStack' :: RollbackStack -> Maybe Text
roleARN} -> Maybe Text
roleARN) (\s :: RollbackStack
s@RollbackStack' {} Maybe Text
a -> RollbackStack
s {$sel:roleARN:RollbackStack' :: Maybe Text
roleARN = Maybe Text
a} :: RollbackStack)

-- | The name that is associated with the stack.
rollbackStack_stackName :: Lens.Lens' RollbackStack Prelude.Text
rollbackStack_stackName :: (Text -> f Text) -> RollbackStack -> f RollbackStack
rollbackStack_stackName = (RollbackStack -> Text)
-> (RollbackStack -> Text -> RollbackStack)
-> Lens RollbackStack RollbackStack Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackStack' {Text
stackName :: Text
$sel:stackName:RollbackStack' :: RollbackStack -> Text
stackName} -> Text
stackName) (\s :: RollbackStack
s@RollbackStack' {} Text
a -> RollbackStack
s {$sel:stackName:RollbackStack' :: Text
stackName = Text
a} :: RollbackStack)

instance Core.AWSRequest RollbackStack where
  type
    AWSResponse RollbackStack =
      RollbackStackResponse
  request :: RollbackStack -> Request RollbackStack
request = Service -> RollbackStack -> Request RollbackStack
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy RollbackStack
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RollbackStack)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse RollbackStack))
-> Logger
-> Service
-> Proxy RollbackStack
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RollbackStack)))
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
"RollbackStackResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Int -> RollbackStackResponse
RollbackStackResponse'
            (Maybe Text -> Int -> RollbackStackResponse)
-> Either String (Maybe Text)
-> Either String (Int -> RollbackStackResponse)
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 -> RollbackStackResponse)
-> Either String Int -> Either String RollbackStackResponse
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 RollbackStack

instance Prelude.NFData RollbackStack

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

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

instance Core.ToQuery RollbackStack where
  toQuery :: RollbackStack -> QueryString
toQuery RollbackStack' {Maybe Text
Text
stackName :: Text
roleARN :: Maybe Text
clientRequestToken :: Maybe Text
$sel:stackName:RollbackStack' :: RollbackStack -> Text
$sel:roleARN:RollbackStack' :: RollbackStack -> Maybe Text
$sel:clientRequestToken:RollbackStack' :: RollbackStack -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"RollbackStack" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-05-15" :: Prelude.ByteString),
        ByteString
"ClientRequestToken" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
clientRequestToken,
        ByteString
"RoleARN" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
roleARN,
        ByteString
"StackName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
stackName
      ]

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

-- |
-- Create a value of 'RollbackStackResponse' 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', 'rollbackStackResponse_stackId' - Unique identifier of the stack.
--
-- 'httpStatus', 'rollbackStackResponse_httpStatus' - The response's http status code.
newRollbackStackResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RollbackStackResponse
newRollbackStackResponse :: Int -> RollbackStackResponse
newRollbackStackResponse Int
pHttpStatus_ =
  RollbackStackResponse' :: Maybe Text -> Int -> RollbackStackResponse
RollbackStackResponse'
    { $sel:stackId:RollbackStackResponse' :: Maybe Text
stackId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RollbackStackResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Unique identifier of the stack.
rollbackStackResponse_stackId :: Lens.Lens' RollbackStackResponse (Prelude.Maybe Prelude.Text)
rollbackStackResponse_stackId :: (Maybe Text -> f (Maybe Text))
-> RollbackStackResponse -> f RollbackStackResponse
rollbackStackResponse_stackId = (RollbackStackResponse -> Maybe Text)
-> (RollbackStackResponse -> Maybe Text -> RollbackStackResponse)
-> Lens
     RollbackStackResponse
     RollbackStackResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackStackResponse' {Maybe Text
stackId :: Maybe Text
$sel:stackId:RollbackStackResponse' :: RollbackStackResponse -> Maybe Text
stackId} -> Maybe Text
stackId) (\s :: RollbackStackResponse
s@RollbackStackResponse' {} Maybe Text
a -> RollbackStackResponse
s {$sel:stackId:RollbackStackResponse' :: Maybe Text
stackId = Maybe Text
a} :: RollbackStackResponse)

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

instance Prelude.NFData RollbackStackResponse