{-# 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.DeleteStack
-- 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)
--
-- Deletes a specified stack. Once the call completes successfully, stack
-- deletion starts. Deleted stacks do not show up in the DescribeStacks API
-- if the deletion has been completed successfully.
module Amazonka.CloudFormation.DeleteStack
  ( -- * Creating a Request
    DeleteStack (..),
    newDeleteStack,

    -- * Request Lenses
    deleteStack_retainResources,
    deleteStack_clientRequestToken,
    deleteStack_roleARN,
    deleteStack_stackName,

    -- * Destructuring the Response
    DeleteStackResponse (..),
    newDeleteStackResponse,
  )
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

-- | The input for DeleteStack action.
--
-- /See:/ 'newDeleteStack' smart constructor.
data DeleteStack = DeleteStack'
  { -- | For stacks in the @DELETE_FAILED@ state, a list of resource logical IDs
    -- that are associated with the resources you want to retain. During
    -- deletion, CloudFormation deletes the stack but does not delete the
    -- retained resources.
    --
    -- Retaining resources is useful when you cannot delete a resource, such as
    -- a non-empty S3 bucket, but you want to delete the stack.
    DeleteStack -> Maybe [Text]
retainResources :: Prelude.Maybe [Prelude.Text],
    -- | A unique identifier for this @DeleteStack@ request. Specify this token
    -- if you plan to retry requests so that CloudFormation knows that you\'re
    -- not attempting to delete a stack with the same name. You might retry
    -- @DeleteStack@ requests to ensure that CloudFormation successfully
    -- received them.
    --
    -- All events triggered by a given stack operation are assigned the same
    -- client request token, which you can use to track operations. For
    -- example, if you execute a @CreateStack@ operation with the token
    -- @token1@, then all the @StackEvents@ generated by that operation will
    -- have @ClientRequestToken@ set as @token1@.
    --
    -- In the console, stack operations display the client request token on the
    -- Events tab. Stack operations that are initiated from the console use the
    -- token format /Console-StackOperation-ID/, which helps you easily
    -- identify the stack operation . For example, if you create a stack using
    -- the console, each stack event would be assigned the same token in the
    -- following format:
    -- @Console-CreateStack-7f59c3cf-00d2-40c7-b2ff-e75db0987002@.
    DeleteStack -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of an Identity and Access Management
    -- (IAM) role that CloudFormation assumes to delete the stack.
    -- CloudFormation uses the role\'s credentials to make calls on your
    -- behalf.
    --
    -- If you don\'t specify a value, CloudFormation uses the role that was
    -- previously associated with the stack. If no role is available,
    -- CloudFormation uses a temporary session that is generated from your user
    -- credentials.
    DeleteStack -> Maybe Text
roleARN :: Prelude.Maybe Prelude.Text,
    -- | The name or the unique stack ID that is associated with the stack.
    DeleteStack -> Text
stackName :: Prelude.Text
  }
  deriving (DeleteStack -> DeleteStack -> Bool
(DeleteStack -> DeleteStack -> Bool)
-> (DeleteStack -> DeleteStack -> Bool) -> Eq DeleteStack
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteStack -> DeleteStack -> Bool
$c/= :: DeleteStack -> DeleteStack -> Bool
== :: DeleteStack -> DeleteStack -> Bool
$c== :: DeleteStack -> DeleteStack -> Bool
Prelude.Eq, ReadPrec [DeleteStack]
ReadPrec DeleteStack
Int -> ReadS DeleteStack
ReadS [DeleteStack]
(Int -> ReadS DeleteStack)
-> ReadS [DeleteStack]
-> ReadPrec DeleteStack
-> ReadPrec [DeleteStack]
-> Read DeleteStack
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteStack]
$creadListPrec :: ReadPrec [DeleteStack]
readPrec :: ReadPrec DeleteStack
$creadPrec :: ReadPrec DeleteStack
readList :: ReadS [DeleteStack]
$creadList :: ReadS [DeleteStack]
readsPrec :: Int -> ReadS DeleteStack
$creadsPrec :: Int -> ReadS DeleteStack
Prelude.Read, Int -> DeleteStack -> ShowS
[DeleteStack] -> ShowS
DeleteStack -> String
(Int -> DeleteStack -> ShowS)
-> (DeleteStack -> String)
-> ([DeleteStack] -> ShowS)
-> Show DeleteStack
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteStack] -> ShowS
$cshowList :: [DeleteStack] -> ShowS
show :: DeleteStack -> String
$cshow :: DeleteStack -> String
showsPrec :: Int -> DeleteStack -> ShowS
$cshowsPrec :: Int -> DeleteStack -> ShowS
Prelude.Show, (forall x. DeleteStack -> Rep DeleteStack x)
-> (forall x. Rep DeleteStack x -> DeleteStack)
-> Generic DeleteStack
forall x. Rep DeleteStack x -> DeleteStack
forall x. DeleteStack -> Rep DeleteStack x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteStack x -> DeleteStack
$cfrom :: forall x. DeleteStack -> Rep DeleteStack x
Prelude.Generic)

-- |
-- Create a value of 'DeleteStack' 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:
--
-- 'retainResources', 'deleteStack_retainResources' - For stacks in the @DELETE_FAILED@ state, a list of resource logical IDs
-- that are associated with the resources you want to retain. During
-- deletion, CloudFormation deletes the stack but does not delete the
-- retained resources.
--
-- Retaining resources is useful when you cannot delete a resource, such as
-- a non-empty S3 bucket, but you want to delete the stack.
--
-- 'clientRequestToken', 'deleteStack_clientRequestToken' - A unique identifier for this @DeleteStack@ request. Specify this token
-- if you plan to retry requests so that CloudFormation knows that you\'re
-- not attempting to delete a stack with the same name. You might retry
-- @DeleteStack@ requests to ensure that CloudFormation successfully
-- received them.
--
-- All events triggered by a given stack operation are assigned the same
-- client request token, which you can use to track operations. For
-- example, if you execute a @CreateStack@ operation with the token
-- @token1@, then all the @StackEvents@ generated by that operation will
-- have @ClientRequestToken@ set as @token1@.
--
-- In the console, stack operations display the client request token on the
-- Events tab. Stack operations that are initiated from the console use the
-- token format /Console-StackOperation-ID/, which helps you easily
-- identify the stack operation . For example, if you create a stack using
-- the console, each stack event would be assigned the same token in the
-- following format:
-- @Console-CreateStack-7f59c3cf-00d2-40c7-b2ff-e75db0987002@.
--
-- 'roleARN', 'deleteStack_roleARN' - The Amazon Resource Name (ARN) of an Identity and Access Management
-- (IAM) role that CloudFormation assumes to delete the stack.
-- CloudFormation uses the role\'s credentials to make calls on your
-- behalf.
--
-- If you don\'t specify a value, CloudFormation uses the role that was
-- previously associated with the stack. If no role is available,
-- CloudFormation uses a temporary session that is generated from your user
-- credentials.
--
-- 'stackName', 'deleteStack_stackName' - The name or the unique stack ID that is associated with the stack.
newDeleteStack ::
  -- | 'stackName'
  Prelude.Text ->
  DeleteStack
newDeleteStack :: Text -> DeleteStack
newDeleteStack Text
pStackName_ =
  DeleteStack' :: Maybe [Text] -> Maybe Text -> Maybe Text -> Text -> DeleteStack
DeleteStack'
    { $sel:retainResources:DeleteStack' :: Maybe [Text]
retainResources = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:clientRequestToken:DeleteStack' :: Maybe Text
clientRequestToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:roleARN:DeleteStack' :: Maybe Text
roleARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stackName:DeleteStack' :: Text
stackName = Text
pStackName_
    }

-- | For stacks in the @DELETE_FAILED@ state, a list of resource logical IDs
-- that are associated with the resources you want to retain. During
-- deletion, CloudFormation deletes the stack but does not delete the
-- retained resources.
--
-- Retaining resources is useful when you cannot delete a resource, such as
-- a non-empty S3 bucket, but you want to delete the stack.
deleteStack_retainResources :: Lens.Lens' DeleteStack (Prelude.Maybe [Prelude.Text])
deleteStack_retainResources :: (Maybe [Text] -> f (Maybe [Text])) -> DeleteStack -> f DeleteStack
deleteStack_retainResources = (DeleteStack -> Maybe [Text])
-> (DeleteStack -> Maybe [Text] -> DeleteStack)
-> Lens DeleteStack DeleteStack (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteStack' {Maybe [Text]
retainResources :: Maybe [Text]
$sel:retainResources:DeleteStack' :: DeleteStack -> Maybe [Text]
retainResources} -> Maybe [Text]
retainResources) (\s :: DeleteStack
s@DeleteStack' {} Maybe [Text]
a -> DeleteStack
s {$sel:retainResources:DeleteStack' :: Maybe [Text]
retainResources = Maybe [Text]
a} :: DeleteStack) ((Maybe [Text] -> f (Maybe [Text]))
 -> DeleteStack -> f DeleteStack)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> DeleteStack
-> f DeleteStack
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A unique identifier for this @DeleteStack@ request. Specify this token
-- if you plan to retry requests so that CloudFormation knows that you\'re
-- not attempting to delete a stack with the same name. You might retry
-- @DeleteStack@ requests to ensure that CloudFormation successfully
-- received them.
--
-- All events triggered by a given stack operation are assigned the same
-- client request token, which you can use to track operations. For
-- example, if you execute a @CreateStack@ operation with the token
-- @token1@, then all the @StackEvents@ generated by that operation will
-- have @ClientRequestToken@ set as @token1@.
--
-- In the console, stack operations display the client request token on the
-- Events tab. Stack operations that are initiated from the console use the
-- token format /Console-StackOperation-ID/, which helps you easily
-- identify the stack operation . For example, if you create a stack using
-- the console, each stack event would be assigned the same token in the
-- following format:
-- @Console-CreateStack-7f59c3cf-00d2-40c7-b2ff-e75db0987002@.
deleteStack_clientRequestToken :: Lens.Lens' DeleteStack (Prelude.Maybe Prelude.Text)
deleteStack_clientRequestToken :: (Maybe Text -> f (Maybe Text)) -> DeleteStack -> f DeleteStack
deleteStack_clientRequestToken = (DeleteStack -> Maybe Text)
-> (DeleteStack -> Maybe Text -> DeleteStack)
-> Lens DeleteStack DeleteStack (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteStack' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:DeleteStack' :: DeleteStack -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: DeleteStack
s@DeleteStack' {} Maybe Text
a -> DeleteStack
s {$sel:clientRequestToken:DeleteStack' :: Maybe Text
clientRequestToken = Maybe Text
a} :: DeleteStack)

-- | The Amazon Resource Name (ARN) of an Identity and Access Management
-- (IAM) role that CloudFormation assumes to delete the stack.
-- CloudFormation uses the role\'s credentials to make calls on your
-- behalf.
--
-- If you don\'t specify a value, CloudFormation uses the role that was
-- previously associated with the stack. If no role is available,
-- CloudFormation uses a temporary session that is generated from your user
-- credentials.
deleteStack_roleARN :: Lens.Lens' DeleteStack (Prelude.Maybe Prelude.Text)
deleteStack_roleARN :: (Maybe Text -> f (Maybe Text)) -> DeleteStack -> f DeleteStack
deleteStack_roleARN = (DeleteStack -> Maybe Text)
-> (DeleteStack -> Maybe Text -> DeleteStack)
-> Lens DeleteStack DeleteStack (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteStack' {Maybe Text
roleARN :: Maybe Text
$sel:roleARN:DeleteStack' :: DeleteStack -> Maybe Text
roleARN} -> Maybe Text
roleARN) (\s :: DeleteStack
s@DeleteStack' {} Maybe Text
a -> DeleteStack
s {$sel:roleARN:DeleteStack' :: Maybe Text
roleARN = Maybe Text
a} :: DeleteStack)

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

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

instance Prelude.Hashable DeleteStack

instance Prelude.NFData DeleteStack

instance Core.ToHeaders DeleteStack where
  toHeaders :: DeleteStack -> [Header]
toHeaders = [Header] -> DeleteStack -> [Header]
forall a b. a -> b -> a
Prelude.const [Header]
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery DeleteStack where
  toQuery :: DeleteStack -> QueryString
toQuery DeleteStack' {Maybe [Text]
Maybe Text
Text
stackName :: Text
roleARN :: Maybe Text
clientRequestToken :: Maybe Text
retainResources :: Maybe [Text]
$sel:stackName:DeleteStack' :: DeleteStack -> Text
$sel:roleARN:DeleteStack' :: DeleteStack -> Maybe Text
$sel:clientRequestToken:DeleteStack' :: DeleteStack -> Maybe Text
$sel:retainResources:DeleteStack' :: DeleteStack -> 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
"DeleteStack" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-05-15" :: Prelude.ByteString),
        ByteString
"RetainResources"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            ( ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member"
                ([Text] -> QueryString) -> Maybe [Text] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
retainResources
            ),
        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:/ 'newDeleteStackResponse' smart constructor.
data DeleteStackResponse = DeleteStackResponse'
  {
  }
  deriving (DeleteStackResponse -> DeleteStackResponse -> Bool
(DeleteStackResponse -> DeleteStackResponse -> Bool)
-> (DeleteStackResponse -> DeleteStackResponse -> Bool)
-> Eq DeleteStackResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteStackResponse -> DeleteStackResponse -> Bool
$c/= :: DeleteStackResponse -> DeleteStackResponse -> Bool
== :: DeleteStackResponse -> DeleteStackResponse -> Bool
$c== :: DeleteStackResponse -> DeleteStackResponse -> Bool
Prelude.Eq, ReadPrec [DeleteStackResponse]
ReadPrec DeleteStackResponse
Int -> ReadS DeleteStackResponse
ReadS [DeleteStackResponse]
(Int -> ReadS DeleteStackResponse)
-> ReadS [DeleteStackResponse]
-> ReadPrec DeleteStackResponse
-> ReadPrec [DeleteStackResponse]
-> Read DeleteStackResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteStackResponse]
$creadListPrec :: ReadPrec [DeleteStackResponse]
readPrec :: ReadPrec DeleteStackResponse
$creadPrec :: ReadPrec DeleteStackResponse
readList :: ReadS [DeleteStackResponse]
$creadList :: ReadS [DeleteStackResponse]
readsPrec :: Int -> ReadS DeleteStackResponse
$creadsPrec :: Int -> ReadS DeleteStackResponse
Prelude.Read, Int -> DeleteStackResponse -> ShowS
[DeleteStackResponse] -> ShowS
DeleteStackResponse -> String
(Int -> DeleteStackResponse -> ShowS)
-> (DeleteStackResponse -> String)
-> ([DeleteStackResponse] -> ShowS)
-> Show DeleteStackResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteStackResponse] -> ShowS
$cshowList :: [DeleteStackResponse] -> ShowS
show :: DeleteStackResponse -> String
$cshow :: DeleteStackResponse -> String
showsPrec :: Int -> DeleteStackResponse -> ShowS
$cshowsPrec :: Int -> DeleteStackResponse -> ShowS
Prelude.Show, (forall x. DeleteStackResponse -> Rep DeleteStackResponse x)
-> (forall x. Rep DeleteStackResponse x -> DeleteStackResponse)
-> Generic DeleteStackResponse
forall x. Rep DeleteStackResponse x -> DeleteStackResponse
forall x. DeleteStackResponse -> Rep DeleteStackResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteStackResponse x -> DeleteStackResponse
$cfrom :: forall x. DeleteStackResponse -> Rep DeleteStackResponse x
Prelude.Generic)

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

instance Prelude.NFData DeleteStackResponse