{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.RollbackConfiguration
-- 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)
module Amazonka.CloudFormation.Types.RollbackConfiguration where

import Amazonka.CloudFormation.Types.RollbackTrigger
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Structure containing the rollback triggers for CloudFormation to monitor
-- during stack creation and updating operations, and for the specified
-- monitoring period afterwards.
--
-- Rollback triggers enable you to have CloudFormation monitor the state of
-- your application during stack creation and updating, and to roll back
-- that operation if the application breaches the threshold of any of the
-- alarms you\'ve specified. For more information, see
-- <http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-rollback-triggers.html Monitor and Roll Back Stack Operations>.
--
-- /See:/ 'newRollbackConfiguration' smart constructor.
data RollbackConfiguration = RollbackConfiguration'
  { -- | The triggers to monitor during stack creation or update actions.
    --
    -- By default, CloudFormation saves the rollback triggers specified for a
    -- stack and applies them to any subsequent update operations for the
    -- stack, unless you specify otherwise. If you do specify rollback triggers
    -- for this parameter, those triggers replace any list of triggers
    -- previously specified for the stack. This means:
    --
    -- -   To use the rollback triggers previously specified for this stack, if
    --     any, don\'t specify this parameter.
    --
    -- -   To specify new or updated rollback triggers, you must specify /all/
    --     the triggers that you want used for this stack, even triggers
    --     you\'ve specifed before (for example, when creating the stack or
    --     during a previous stack update). Any triggers that you don\'t
    --     include in the updated list of triggers are no longer applied to the
    --     stack.
    --
    -- -   To remove all currently specified triggers, specify an empty list
    --     for this parameter.
    --
    -- If a specified trigger is missing, the entire stack operation fails and
    -- is rolled back.
    RollbackConfiguration -> Maybe [RollbackTrigger]
rollbackTriggers :: Prelude.Maybe [RollbackTrigger],
    -- | The amount of time, in minutes, during which CloudFormation should
    -- monitor all the rollback triggers after the stack creation or update
    -- operation deploys all necessary resources.
    --
    -- The default is 0 minutes.
    --
    -- If you specify a monitoring period but do not specify any rollback
    -- triggers, CloudFormation still waits the specified period of time before
    -- cleaning up old resources after update operations. You can use this
    -- monitoring period to perform any manual stack validation desired, and
    -- manually cancel the stack creation or update (using
    -- <https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CancelUpdateStack.html CancelUpdateStack>,
    -- for example) as necessary.
    --
    -- If you specify 0 for this parameter, CloudFormation still monitors the
    -- specified rollback triggers during stack creation and update operations.
    -- Then, for update operations, it begins disposing of old resources
    -- immediately once the operation completes.
    RollbackConfiguration -> Maybe Natural
monitoringTimeInMinutes :: Prelude.Maybe Prelude.Natural
  }
  deriving (RollbackConfiguration -> RollbackConfiguration -> Bool
(RollbackConfiguration -> RollbackConfiguration -> Bool)
-> (RollbackConfiguration -> RollbackConfiguration -> Bool)
-> Eq RollbackConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RollbackConfiguration -> RollbackConfiguration -> Bool
$c/= :: RollbackConfiguration -> RollbackConfiguration -> Bool
== :: RollbackConfiguration -> RollbackConfiguration -> Bool
$c== :: RollbackConfiguration -> RollbackConfiguration -> Bool
Prelude.Eq, ReadPrec [RollbackConfiguration]
ReadPrec RollbackConfiguration
Int -> ReadS RollbackConfiguration
ReadS [RollbackConfiguration]
(Int -> ReadS RollbackConfiguration)
-> ReadS [RollbackConfiguration]
-> ReadPrec RollbackConfiguration
-> ReadPrec [RollbackConfiguration]
-> Read RollbackConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RollbackConfiguration]
$creadListPrec :: ReadPrec [RollbackConfiguration]
readPrec :: ReadPrec RollbackConfiguration
$creadPrec :: ReadPrec RollbackConfiguration
readList :: ReadS [RollbackConfiguration]
$creadList :: ReadS [RollbackConfiguration]
readsPrec :: Int -> ReadS RollbackConfiguration
$creadsPrec :: Int -> ReadS RollbackConfiguration
Prelude.Read, Int -> RollbackConfiguration -> ShowS
[RollbackConfiguration] -> ShowS
RollbackConfiguration -> String
(Int -> RollbackConfiguration -> ShowS)
-> (RollbackConfiguration -> String)
-> ([RollbackConfiguration] -> ShowS)
-> Show RollbackConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RollbackConfiguration] -> ShowS
$cshowList :: [RollbackConfiguration] -> ShowS
show :: RollbackConfiguration -> String
$cshow :: RollbackConfiguration -> String
showsPrec :: Int -> RollbackConfiguration -> ShowS
$cshowsPrec :: Int -> RollbackConfiguration -> ShowS
Prelude.Show, (forall x. RollbackConfiguration -> Rep RollbackConfiguration x)
-> (forall x. Rep RollbackConfiguration x -> RollbackConfiguration)
-> Generic RollbackConfiguration
forall x. Rep RollbackConfiguration x -> RollbackConfiguration
forall x. RollbackConfiguration -> Rep RollbackConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RollbackConfiguration x -> RollbackConfiguration
$cfrom :: forall x. RollbackConfiguration -> Rep RollbackConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'RollbackConfiguration' 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:
--
-- 'rollbackTriggers', 'rollbackConfiguration_rollbackTriggers' - The triggers to monitor during stack creation or update actions.
--
-- By default, CloudFormation saves the rollback triggers specified for a
-- stack and applies them to any subsequent update operations for the
-- stack, unless you specify otherwise. If you do specify rollback triggers
-- for this parameter, those triggers replace any list of triggers
-- previously specified for the stack. This means:
--
-- -   To use the rollback triggers previously specified for this stack, if
--     any, don\'t specify this parameter.
--
-- -   To specify new or updated rollback triggers, you must specify /all/
--     the triggers that you want used for this stack, even triggers
--     you\'ve specifed before (for example, when creating the stack or
--     during a previous stack update). Any triggers that you don\'t
--     include in the updated list of triggers are no longer applied to the
--     stack.
--
-- -   To remove all currently specified triggers, specify an empty list
--     for this parameter.
--
-- If a specified trigger is missing, the entire stack operation fails and
-- is rolled back.
--
-- 'monitoringTimeInMinutes', 'rollbackConfiguration_monitoringTimeInMinutes' - The amount of time, in minutes, during which CloudFormation should
-- monitor all the rollback triggers after the stack creation or update
-- operation deploys all necessary resources.
--
-- The default is 0 minutes.
--
-- If you specify a monitoring period but do not specify any rollback
-- triggers, CloudFormation still waits the specified period of time before
-- cleaning up old resources after update operations. You can use this
-- monitoring period to perform any manual stack validation desired, and
-- manually cancel the stack creation or update (using
-- <https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CancelUpdateStack.html CancelUpdateStack>,
-- for example) as necessary.
--
-- If you specify 0 for this parameter, CloudFormation still monitors the
-- specified rollback triggers during stack creation and update operations.
-- Then, for update operations, it begins disposing of old resources
-- immediately once the operation completes.
newRollbackConfiguration ::
  RollbackConfiguration
newRollbackConfiguration :: RollbackConfiguration
newRollbackConfiguration =
  RollbackConfiguration' :: Maybe [RollbackTrigger] -> Maybe Natural -> RollbackConfiguration
RollbackConfiguration'
    { $sel:rollbackTriggers:RollbackConfiguration' :: Maybe [RollbackTrigger]
rollbackTriggers =
        Maybe [RollbackTrigger]
forall a. Maybe a
Prelude.Nothing,
      $sel:monitoringTimeInMinutes:RollbackConfiguration' :: Maybe Natural
monitoringTimeInMinutes = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The triggers to monitor during stack creation or update actions.
--
-- By default, CloudFormation saves the rollback triggers specified for a
-- stack and applies them to any subsequent update operations for the
-- stack, unless you specify otherwise. If you do specify rollback triggers
-- for this parameter, those triggers replace any list of triggers
-- previously specified for the stack. This means:
--
-- -   To use the rollback triggers previously specified for this stack, if
--     any, don\'t specify this parameter.
--
-- -   To specify new or updated rollback triggers, you must specify /all/
--     the triggers that you want used for this stack, even triggers
--     you\'ve specifed before (for example, when creating the stack or
--     during a previous stack update). Any triggers that you don\'t
--     include in the updated list of triggers are no longer applied to the
--     stack.
--
-- -   To remove all currently specified triggers, specify an empty list
--     for this parameter.
--
-- If a specified trigger is missing, the entire stack operation fails and
-- is rolled back.
rollbackConfiguration_rollbackTriggers :: Lens.Lens' RollbackConfiguration (Prelude.Maybe [RollbackTrigger])
rollbackConfiguration_rollbackTriggers :: (Maybe [RollbackTrigger] -> f (Maybe [RollbackTrigger]))
-> RollbackConfiguration -> f RollbackConfiguration
rollbackConfiguration_rollbackTriggers = (RollbackConfiguration -> Maybe [RollbackTrigger])
-> (RollbackConfiguration
    -> Maybe [RollbackTrigger] -> RollbackConfiguration)
-> Lens
     RollbackConfiguration
     RollbackConfiguration
     (Maybe [RollbackTrigger])
     (Maybe [RollbackTrigger])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackConfiguration' {Maybe [RollbackTrigger]
rollbackTriggers :: Maybe [RollbackTrigger]
$sel:rollbackTriggers:RollbackConfiguration' :: RollbackConfiguration -> Maybe [RollbackTrigger]
rollbackTriggers} -> Maybe [RollbackTrigger]
rollbackTriggers) (\s :: RollbackConfiguration
s@RollbackConfiguration' {} Maybe [RollbackTrigger]
a -> RollbackConfiguration
s {$sel:rollbackTriggers:RollbackConfiguration' :: Maybe [RollbackTrigger]
rollbackTriggers = Maybe [RollbackTrigger]
a} :: RollbackConfiguration) ((Maybe [RollbackTrigger] -> f (Maybe [RollbackTrigger]))
 -> RollbackConfiguration -> f RollbackConfiguration)
-> ((Maybe [RollbackTrigger] -> f (Maybe [RollbackTrigger]))
    -> Maybe [RollbackTrigger] -> f (Maybe [RollbackTrigger]))
-> (Maybe [RollbackTrigger] -> f (Maybe [RollbackTrigger]))
-> RollbackConfiguration
-> f RollbackConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [RollbackTrigger]
  [RollbackTrigger]
  [RollbackTrigger]
  [RollbackTrigger]
-> Iso
     (Maybe [RollbackTrigger])
     (Maybe [RollbackTrigger])
     (Maybe [RollbackTrigger])
     (Maybe [RollbackTrigger])
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
  [RollbackTrigger]
  [RollbackTrigger]
  [RollbackTrigger]
  [RollbackTrigger]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The amount of time, in minutes, during which CloudFormation should
-- monitor all the rollback triggers after the stack creation or update
-- operation deploys all necessary resources.
--
-- The default is 0 minutes.
--
-- If you specify a monitoring period but do not specify any rollback
-- triggers, CloudFormation still waits the specified period of time before
-- cleaning up old resources after update operations. You can use this
-- monitoring period to perform any manual stack validation desired, and
-- manually cancel the stack creation or update (using
-- <https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CancelUpdateStack.html CancelUpdateStack>,
-- for example) as necessary.
--
-- If you specify 0 for this parameter, CloudFormation still monitors the
-- specified rollback triggers during stack creation and update operations.
-- Then, for update operations, it begins disposing of old resources
-- immediately once the operation completes.
rollbackConfiguration_monitoringTimeInMinutes :: Lens.Lens' RollbackConfiguration (Prelude.Maybe Prelude.Natural)
rollbackConfiguration_monitoringTimeInMinutes :: (Maybe Natural -> f (Maybe Natural))
-> RollbackConfiguration -> f RollbackConfiguration
rollbackConfiguration_monitoringTimeInMinutes = (RollbackConfiguration -> Maybe Natural)
-> (RollbackConfiguration
    -> Maybe Natural -> RollbackConfiguration)
-> Lens
     RollbackConfiguration
     RollbackConfiguration
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackConfiguration' {Maybe Natural
monitoringTimeInMinutes :: Maybe Natural
$sel:monitoringTimeInMinutes:RollbackConfiguration' :: RollbackConfiguration -> Maybe Natural
monitoringTimeInMinutes} -> Maybe Natural
monitoringTimeInMinutes) (\s :: RollbackConfiguration
s@RollbackConfiguration' {} Maybe Natural
a -> RollbackConfiguration
s {$sel:monitoringTimeInMinutes:RollbackConfiguration' :: Maybe Natural
monitoringTimeInMinutes = Maybe Natural
a} :: RollbackConfiguration)

instance Core.FromXML RollbackConfiguration where
  parseXML :: [Node] -> Either String RollbackConfiguration
parseXML [Node]
x =
    Maybe [RollbackTrigger] -> Maybe Natural -> RollbackConfiguration
RollbackConfiguration'
      (Maybe [RollbackTrigger] -> Maybe Natural -> RollbackConfiguration)
-> Either String (Maybe [RollbackTrigger])
-> Either String (Maybe Natural -> RollbackConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"RollbackTriggers"
                      Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [RollbackTrigger]))
-> Either String (Maybe [RollbackTrigger])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [RollbackTrigger])
-> [Node] -> Either String (Maybe [RollbackTrigger])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [RollbackTrigger]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either String (Maybe Natural -> RollbackConfiguration)
-> Either String (Maybe Natural)
-> Either String RollbackConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Natural)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MonitoringTimeInMinutes")

instance Prelude.Hashable RollbackConfiguration

instance Prelude.NFData RollbackConfiguration

instance Core.ToQuery RollbackConfiguration where
  toQuery :: RollbackConfiguration -> QueryString
toQuery RollbackConfiguration' {Maybe Natural
Maybe [RollbackTrigger]
monitoringTimeInMinutes :: Maybe Natural
rollbackTriggers :: Maybe [RollbackTrigger]
$sel:monitoringTimeInMinutes:RollbackConfiguration' :: RollbackConfiguration -> Maybe Natural
$sel:rollbackTriggers:RollbackConfiguration' :: RollbackConfiguration -> Maybe [RollbackTrigger]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"RollbackTriggers"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            ( ByteString -> [RollbackTrigger] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member"
                ([RollbackTrigger] -> QueryString)
-> Maybe [RollbackTrigger] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [RollbackTrigger]
rollbackTriggers
            ),
        ByteString
"MonitoringTimeInMinutes"
          ByteString -> Maybe Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Natural
monitoringTimeInMinutes
      ]