{-# 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.DetectStackResourceDrift
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns information about whether a resource\'s actual configuration
-- differs, or has /drifted/, from it\'s expected configuration, as defined
-- in the stack template and any values specified as template parameters.
-- This information includes actual and expected property values for
-- resources in which CloudFormation detects drift. Only resource
-- properties explicitly defined in the stack template are checked for
-- drift. For more information about stack and resource drift, see
-- <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift.html Detecting Unregulated Configuration Changes to Stacks and Resources>.
--
-- Use @DetectStackResourceDrift@ to detect drift on individual resources,
-- or DetectStackDrift to detect drift on all resources in a given stack
-- that support drift detection.
--
-- Resources that don\'t currently support drift detection can\'t be
-- checked. For a list of resources that support drift detection, see
-- <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift-resource-list.html Resources that Support Drift Detection>.
module Amazonka.CloudFormation.DetectStackResourceDrift
  ( -- * Creating a Request
    DetectStackResourceDrift (..),
    newDetectStackResourceDrift,

    -- * Request Lenses
    detectStackResourceDrift_stackName,
    detectStackResourceDrift_logicalResourceId,

    -- * Destructuring the Response
    DetectStackResourceDriftResponse (..),
    newDetectStackResourceDriftResponse,

    -- * Response Lenses
    detectStackResourceDriftResponse_httpStatus,
    detectStackResourceDriftResponse_stackResourceDrift,
  )
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:/ 'newDetectStackResourceDrift' smart constructor.
data DetectStackResourceDrift = DetectStackResourceDrift'
  { -- | The name of the stack to which the resource belongs.
    DetectStackResourceDrift -> Text
stackName :: Prelude.Text,
    -- | The logical name of the resource for which to return drift information.
    DetectStackResourceDrift -> Text
logicalResourceId :: Prelude.Text
  }
  deriving (DetectStackResourceDrift -> DetectStackResourceDrift -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectStackResourceDrift -> DetectStackResourceDrift -> Bool
$c/= :: DetectStackResourceDrift -> DetectStackResourceDrift -> Bool
== :: DetectStackResourceDrift -> DetectStackResourceDrift -> Bool
$c== :: DetectStackResourceDrift -> DetectStackResourceDrift -> Bool
Prelude.Eq, ReadPrec [DetectStackResourceDrift]
ReadPrec DetectStackResourceDrift
Int -> ReadS DetectStackResourceDrift
ReadS [DetectStackResourceDrift]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectStackResourceDrift]
$creadListPrec :: ReadPrec [DetectStackResourceDrift]
readPrec :: ReadPrec DetectStackResourceDrift
$creadPrec :: ReadPrec DetectStackResourceDrift
readList :: ReadS [DetectStackResourceDrift]
$creadList :: ReadS [DetectStackResourceDrift]
readsPrec :: Int -> ReadS DetectStackResourceDrift
$creadsPrec :: Int -> ReadS DetectStackResourceDrift
Prelude.Read, Int -> DetectStackResourceDrift -> ShowS
[DetectStackResourceDrift] -> ShowS
DetectStackResourceDrift -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectStackResourceDrift] -> ShowS
$cshowList :: [DetectStackResourceDrift] -> ShowS
show :: DetectStackResourceDrift -> String
$cshow :: DetectStackResourceDrift -> String
showsPrec :: Int -> DetectStackResourceDrift -> ShowS
$cshowsPrec :: Int -> DetectStackResourceDrift -> ShowS
Prelude.Show, forall x.
Rep DetectStackResourceDrift x -> DetectStackResourceDrift
forall x.
DetectStackResourceDrift -> Rep DetectStackResourceDrift x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DetectStackResourceDrift x -> DetectStackResourceDrift
$cfrom :: forall x.
DetectStackResourceDrift -> Rep DetectStackResourceDrift x
Prelude.Generic)

-- |
-- Create a value of 'DetectStackResourceDrift' 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:
--
-- 'stackName', 'detectStackResourceDrift_stackName' - The name of the stack to which the resource belongs.
--
-- 'logicalResourceId', 'detectStackResourceDrift_logicalResourceId' - The logical name of the resource for which to return drift information.
newDetectStackResourceDrift ::
  -- | 'stackName'
  Prelude.Text ->
  -- | 'logicalResourceId'
  Prelude.Text ->
  DetectStackResourceDrift
newDetectStackResourceDrift :: Text -> Text -> DetectStackResourceDrift
newDetectStackResourceDrift
  Text
pStackName_
  Text
pLogicalResourceId_ =
    DetectStackResourceDrift'
      { $sel:stackName:DetectStackResourceDrift' :: Text
stackName = Text
pStackName_,
        $sel:logicalResourceId:DetectStackResourceDrift' :: Text
logicalResourceId = Text
pLogicalResourceId_
      }

-- | The name of the stack to which the resource belongs.
detectStackResourceDrift_stackName :: Lens.Lens' DetectStackResourceDrift Prelude.Text
detectStackResourceDrift_stackName :: Lens' DetectStackResourceDrift Text
detectStackResourceDrift_stackName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectStackResourceDrift' {Text
stackName :: Text
$sel:stackName:DetectStackResourceDrift' :: DetectStackResourceDrift -> Text
stackName} -> Text
stackName) (\s :: DetectStackResourceDrift
s@DetectStackResourceDrift' {} Text
a -> DetectStackResourceDrift
s {$sel:stackName:DetectStackResourceDrift' :: Text
stackName = Text
a} :: DetectStackResourceDrift)

-- | The logical name of the resource for which to return drift information.
detectStackResourceDrift_logicalResourceId :: Lens.Lens' DetectStackResourceDrift Prelude.Text
detectStackResourceDrift_logicalResourceId :: Lens' DetectStackResourceDrift Text
detectStackResourceDrift_logicalResourceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectStackResourceDrift' {Text
logicalResourceId :: Text
$sel:logicalResourceId:DetectStackResourceDrift' :: DetectStackResourceDrift -> Text
logicalResourceId} -> Text
logicalResourceId) (\s :: DetectStackResourceDrift
s@DetectStackResourceDrift' {} Text
a -> DetectStackResourceDrift
s {$sel:logicalResourceId:DetectStackResourceDrift' :: Text
logicalResourceId = Text
a} :: DetectStackResourceDrift)

instance Core.AWSRequest DetectStackResourceDrift where
  type
    AWSResponse DetectStackResourceDrift =
      DetectStackResourceDriftResponse
  request :: (Service -> Service)
-> DetectStackResourceDrift -> Request DetectStackResourceDrift
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 DetectStackResourceDrift
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DetectStackResourceDrift)))
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
"DetectStackResourceDriftResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> StackResourceDrift -> DetectStackResourceDriftResponse
DetectStackResourceDriftResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"StackResourceDrift")
      )

instance Prelude.Hashable DetectStackResourceDrift where
  hashWithSalt :: Int -> DetectStackResourceDrift -> Int
hashWithSalt Int
_salt DetectStackResourceDrift' {Text
logicalResourceId :: Text
stackName :: Text
$sel:logicalResourceId:DetectStackResourceDrift' :: DetectStackResourceDrift -> Text
$sel:stackName:DetectStackResourceDrift' :: DetectStackResourceDrift -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
stackName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
logicalResourceId

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

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

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

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

-- | /See:/ 'newDetectStackResourceDriftResponse' smart constructor.
data DetectStackResourceDriftResponse = DetectStackResourceDriftResponse'
  { -- | The response's http status code.
    DetectStackResourceDriftResponse -> Int
httpStatus :: Prelude.Int,
    -- | Information about whether the resource\'s actual configuration has
    -- drifted from its expected template configuration, including actual and
    -- expected property values and any differences detected.
    DetectStackResourceDriftResponse -> StackResourceDrift
stackResourceDrift :: StackResourceDrift
  }
  deriving (DetectStackResourceDriftResponse
-> DetectStackResourceDriftResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectStackResourceDriftResponse
-> DetectStackResourceDriftResponse -> Bool
$c/= :: DetectStackResourceDriftResponse
-> DetectStackResourceDriftResponse -> Bool
== :: DetectStackResourceDriftResponse
-> DetectStackResourceDriftResponse -> Bool
$c== :: DetectStackResourceDriftResponse
-> DetectStackResourceDriftResponse -> Bool
Prelude.Eq, ReadPrec [DetectStackResourceDriftResponse]
ReadPrec DetectStackResourceDriftResponse
Int -> ReadS DetectStackResourceDriftResponse
ReadS [DetectStackResourceDriftResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectStackResourceDriftResponse]
$creadListPrec :: ReadPrec [DetectStackResourceDriftResponse]
readPrec :: ReadPrec DetectStackResourceDriftResponse
$creadPrec :: ReadPrec DetectStackResourceDriftResponse
readList :: ReadS [DetectStackResourceDriftResponse]
$creadList :: ReadS [DetectStackResourceDriftResponse]
readsPrec :: Int -> ReadS DetectStackResourceDriftResponse
$creadsPrec :: Int -> ReadS DetectStackResourceDriftResponse
Prelude.Read, Int -> DetectStackResourceDriftResponse -> ShowS
[DetectStackResourceDriftResponse] -> ShowS
DetectStackResourceDriftResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectStackResourceDriftResponse] -> ShowS
$cshowList :: [DetectStackResourceDriftResponse] -> ShowS
show :: DetectStackResourceDriftResponse -> String
$cshow :: DetectStackResourceDriftResponse -> String
showsPrec :: Int -> DetectStackResourceDriftResponse -> ShowS
$cshowsPrec :: Int -> DetectStackResourceDriftResponse -> ShowS
Prelude.Show, forall x.
Rep DetectStackResourceDriftResponse x
-> DetectStackResourceDriftResponse
forall x.
DetectStackResourceDriftResponse
-> Rep DetectStackResourceDriftResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DetectStackResourceDriftResponse x
-> DetectStackResourceDriftResponse
$cfrom :: forall x.
DetectStackResourceDriftResponse
-> Rep DetectStackResourceDriftResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetectStackResourceDriftResponse' 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:
--
-- 'httpStatus', 'detectStackResourceDriftResponse_httpStatus' - The response's http status code.
--
-- 'stackResourceDrift', 'detectStackResourceDriftResponse_stackResourceDrift' - Information about whether the resource\'s actual configuration has
-- drifted from its expected template configuration, including actual and
-- expected property values and any differences detected.
newDetectStackResourceDriftResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'stackResourceDrift'
  StackResourceDrift ->
  DetectStackResourceDriftResponse
newDetectStackResourceDriftResponse :: Int -> StackResourceDrift -> DetectStackResourceDriftResponse
newDetectStackResourceDriftResponse
  Int
pHttpStatus_
  StackResourceDrift
pStackResourceDrift_ =
    DetectStackResourceDriftResponse'
      { $sel:httpStatus:DetectStackResourceDriftResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:stackResourceDrift:DetectStackResourceDriftResponse' :: StackResourceDrift
stackResourceDrift = StackResourceDrift
pStackResourceDrift_
      }

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

-- | Information about whether the resource\'s actual configuration has
-- drifted from its expected template configuration, including actual and
-- expected property values and any differences detected.
detectStackResourceDriftResponse_stackResourceDrift :: Lens.Lens' DetectStackResourceDriftResponse StackResourceDrift
detectStackResourceDriftResponse_stackResourceDrift :: Lens' DetectStackResourceDriftResponse StackResourceDrift
detectStackResourceDriftResponse_stackResourceDrift = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectStackResourceDriftResponse' {StackResourceDrift
stackResourceDrift :: StackResourceDrift
$sel:stackResourceDrift:DetectStackResourceDriftResponse' :: DetectStackResourceDriftResponse -> StackResourceDrift
stackResourceDrift} -> StackResourceDrift
stackResourceDrift) (\s :: DetectStackResourceDriftResponse
s@DetectStackResourceDriftResponse' {} StackResourceDrift
a -> DetectStackResourceDriftResponse
s {$sel:stackResourceDrift:DetectStackResourceDriftResponse' :: StackResourceDrift
stackResourceDrift = StackResourceDrift
a} :: DetectStackResourceDriftResponse)

instance
  Prelude.NFData
    DetectStackResourceDriftResponse
  where
  rnf :: DetectStackResourceDriftResponse -> ()
rnf DetectStackResourceDriftResponse' {Int
StackResourceDrift
stackResourceDrift :: StackResourceDrift
httpStatus :: Int
$sel:stackResourceDrift:DetectStackResourceDriftResponse' :: DetectStackResourceDriftResponse -> StackResourceDrift
$sel:httpStatus:DetectStackResourceDriftResponse' :: DetectStackResourceDriftResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf StackResourceDrift
stackResourceDrift