{-# 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.CodeDeploy.Types.BlueInstanceTerminationOption
-- 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.CodeDeploy.Types.BlueInstanceTerminationOption where

import Amazonka.CodeDeploy.Types.InstanceAction
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about whether instances in the original environment are
-- terminated when a blue\/green deployment is successful.
-- @BlueInstanceTerminationOption@ does not apply to Lambda deployments.
--
-- /See:/ 'newBlueInstanceTerminationOption' smart constructor.
data BlueInstanceTerminationOption = BlueInstanceTerminationOption'
  { -- | The action to take on instances in the original environment after a
    -- successful blue\/green deployment.
    --
    -- -   @TERMINATE@: Instances are terminated after a specified wait time.
    --
    -- -   @KEEP_ALIVE@: Instances are left running after they are deregistered
    --     from the load balancer and removed from the deployment group.
    BlueInstanceTerminationOption -> Maybe InstanceAction
action :: Prelude.Maybe InstanceAction,
    -- | For an Amazon EC2 deployment, the number of minutes to wait after a
    -- successful blue\/green deployment before terminating instances from the
    -- original environment.
    --
    -- For an Amazon ECS deployment, the number of minutes before deleting the
    -- original (blue) task set. During an Amazon ECS deployment, CodeDeploy
    -- shifts traffic from the original (blue) task set to a replacement
    -- (green) task set.
    --
    -- The maximum setting is 2880 minutes (2 days).
    BlueInstanceTerminationOption -> Maybe Int
terminationWaitTimeInMinutes :: Prelude.Maybe Prelude.Int
  }
  deriving (BlueInstanceTerminationOption
-> BlueInstanceTerminationOption -> Bool
(BlueInstanceTerminationOption
 -> BlueInstanceTerminationOption -> Bool)
-> (BlueInstanceTerminationOption
    -> BlueInstanceTerminationOption -> Bool)
-> Eq BlueInstanceTerminationOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlueInstanceTerminationOption
-> BlueInstanceTerminationOption -> Bool
$c/= :: BlueInstanceTerminationOption
-> BlueInstanceTerminationOption -> Bool
== :: BlueInstanceTerminationOption
-> BlueInstanceTerminationOption -> Bool
$c== :: BlueInstanceTerminationOption
-> BlueInstanceTerminationOption -> Bool
Prelude.Eq, ReadPrec [BlueInstanceTerminationOption]
ReadPrec BlueInstanceTerminationOption
Int -> ReadS BlueInstanceTerminationOption
ReadS [BlueInstanceTerminationOption]
(Int -> ReadS BlueInstanceTerminationOption)
-> ReadS [BlueInstanceTerminationOption]
-> ReadPrec BlueInstanceTerminationOption
-> ReadPrec [BlueInstanceTerminationOption]
-> Read BlueInstanceTerminationOption
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BlueInstanceTerminationOption]
$creadListPrec :: ReadPrec [BlueInstanceTerminationOption]
readPrec :: ReadPrec BlueInstanceTerminationOption
$creadPrec :: ReadPrec BlueInstanceTerminationOption
readList :: ReadS [BlueInstanceTerminationOption]
$creadList :: ReadS [BlueInstanceTerminationOption]
readsPrec :: Int -> ReadS BlueInstanceTerminationOption
$creadsPrec :: Int -> ReadS BlueInstanceTerminationOption
Prelude.Read, Int -> BlueInstanceTerminationOption -> ShowS
[BlueInstanceTerminationOption] -> ShowS
BlueInstanceTerminationOption -> String
(Int -> BlueInstanceTerminationOption -> ShowS)
-> (BlueInstanceTerminationOption -> String)
-> ([BlueInstanceTerminationOption] -> ShowS)
-> Show BlueInstanceTerminationOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlueInstanceTerminationOption] -> ShowS
$cshowList :: [BlueInstanceTerminationOption] -> ShowS
show :: BlueInstanceTerminationOption -> String
$cshow :: BlueInstanceTerminationOption -> String
showsPrec :: Int -> BlueInstanceTerminationOption -> ShowS
$cshowsPrec :: Int -> BlueInstanceTerminationOption -> ShowS
Prelude.Show, (forall x.
 BlueInstanceTerminationOption
 -> Rep BlueInstanceTerminationOption x)
-> (forall x.
    Rep BlueInstanceTerminationOption x
    -> BlueInstanceTerminationOption)
-> Generic BlueInstanceTerminationOption
forall x.
Rep BlueInstanceTerminationOption x
-> BlueInstanceTerminationOption
forall x.
BlueInstanceTerminationOption
-> Rep BlueInstanceTerminationOption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BlueInstanceTerminationOption x
-> BlueInstanceTerminationOption
$cfrom :: forall x.
BlueInstanceTerminationOption
-> Rep BlueInstanceTerminationOption x
Prelude.Generic)

-- |
-- Create a value of 'BlueInstanceTerminationOption' 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:
--
-- 'action', 'blueInstanceTerminationOption_action' - The action to take on instances in the original environment after a
-- successful blue\/green deployment.
--
-- -   @TERMINATE@: Instances are terminated after a specified wait time.
--
-- -   @KEEP_ALIVE@: Instances are left running after they are deregistered
--     from the load balancer and removed from the deployment group.
--
-- 'terminationWaitTimeInMinutes', 'blueInstanceTerminationOption_terminationWaitTimeInMinutes' - For an Amazon EC2 deployment, the number of minutes to wait after a
-- successful blue\/green deployment before terminating instances from the
-- original environment.
--
-- For an Amazon ECS deployment, the number of minutes before deleting the
-- original (blue) task set. During an Amazon ECS deployment, CodeDeploy
-- shifts traffic from the original (blue) task set to a replacement
-- (green) task set.
--
-- The maximum setting is 2880 minutes (2 days).
newBlueInstanceTerminationOption ::
  BlueInstanceTerminationOption
newBlueInstanceTerminationOption :: BlueInstanceTerminationOption
newBlueInstanceTerminationOption =
  BlueInstanceTerminationOption' :: Maybe InstanceAction -> Maybe Int -> BlueInstanceTerminationOption
BlueInstanceTerminationOption'
    { $sel:action:BlueInstanceTerminationOption' :: Maybe InstanceAction
action =
        Maybe InstanceAction
forall a. Maybe a
Prelude.Nothing,
      $sel:terminationWaitTimeInMinutes:BlueInstanceTerminationOption' :: Maybe Int
terminationWaitTimeInMinutes =
        Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The action to take on instances in the original environment after a
-- successful blue\/green deployment.
--
-- -   @TERMINATE@: Instances are terminated after a specified wait time.
--
-- -   @KEEP_ALIVE@: Instances are left running after they are deregistered
--     from the load balancer and removed from the deployment group.
blueInstanceTerminationOption_action :: Lens.Lens' BlueInstanceTerminationOption (Prelude.Maybe InstanceAction)
blueInstanceTerminationOption_action :: (Maybe InstanceAction -> f (Maybe InstanceAction))
-> BlueInstanceTerminationOption -> f BlueInstanceTerminationOption
blueInstanceTerminationOption_action = (BlueInstanceTerminationOption -> Maybe InstanceAction)
-> (BlueInstanceTerminationOption
    -> Maybe InstanceAction -> BlueInstanceTerminationOption)
-> Lens
     BlueInstanceTerminationOption
     BlueInstanceTerminationOption
     (Maybe InstanceAction)
     (Maybe InstanceAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlueInstanceTerminationOption' {Maybe InstanceAction
action :: Maybe InstanceAction
$sel:action:BlueInstanceTerminationOption' :: BlueInstanceTerminationOption -> Maybe InstanceAction
action} -> Maybe InstanceAction
action) (\s :: BlueInstanceTerminationOption
s@BlueInstanceTerminationOption' {} Maybe InstanceAction
a -> BlueInstanceTerminationOption
s {$sel:action:BlueInstanceTerminationOption' :: Maybe InstanceAction
action = Maybe InstanceAction
a} :: BlueInstanceTerminationOption)

-- | For an Amazon EC2 deployment, the number of minutes to wait after a
-- successful blue\/green deployment before terminating instances from the
-- original environment.
--
-- For an Amazon ECS deployment, the number of minutes before deleting the
-- original (blue) task set. During an Amazon ECS deployment, CodeDeploy
-- shifts traffic from the original (blue) task set to a replacement
-- (green) task set.
--
-- The maximum setting is 2880 minutes (2 days).
blueInstanceTerminationOption_terminationWaitTimeInMinutes :: Lens.Lens' BlueInstanceTerminationOption (Prelude.Maybe Prelude.Int)
blueInstanceTerminationOption_terminationWaitTimeInMinutes :: (Maybe Int -> f (Maybe Int))
-> BlueInstanceTerminationOption -> f BlueInstanceTerminationOption
blueInstanceTerminationOption_terminationWaitTimeInMinutes = (BlueInstanceTerminationOption -> Maybe Int)
-> (BlueInstanceTerminationOption
    -> Maybe Int -> BlueInstanceTerminationOption)
-> Lens
     BlueInstanceTerminationOption
     BlueInstanceTerminationOption
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlueInstanceTerminationOption' {Maybe Int
terminationWaitTimeInMinutes :: Maybe Int
$sel:terminationWaitTimeInMinutes:BlueInstanceTerminationOption' :: BlueInstanceTerminationOption -> Maybe Int
terminationWaitTimeInMinutes} -> Maybe Int
terminationWaitTimeInMinutes) (\s :: BlueInstanceTerminationOption
s@BlueInstanceTerminationOption' {} Maybe Int
a -> BlueInstanceTerminationOption
s {$sel:terminationWaitTimeInMinutes:BlueInstanceTerminationOption' :: Maybe Int
terminationWaitTimeInMinutes = Maybe Int
a} :: BlueInstanceTerminationOption)

instance Core.FromJSON BlueInstanceTerminationOption where
  parseJSON :: Value -> Parser BlueInstanceTerminationOption
parseJSON =
    String
-> (Object -> Parser BlueInstanceTerminationOption)
-> Value
-> Parser BlueInstanceTerminationOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"BlueInstanceTerminationOption"
      ( \Object
x ->
          Maybe InstanceAction -> Maybe Int -> BlueInstanceTerminationOption
BlueInstanceTerminationOption'
            (Maybe InstanceAction
 -> Maybe Int -> BlueInstanceTerminationOption)
-> Parser (Maybe InstanceAction)
-> Parser (Maybe Int -> BlueInstanceTerminationOption)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe InstanceAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"action")
            Parser (Maybe Int -> BlueInstanceTerminationOption)
-> Parser (Maybe Int) -> Parser BlueInstanceTerminationOption
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"terminationWaitTimeInMinutes")
      )

instance
  Prelude.Hashable
    BlueInstanceTerminationOption

instance Prelude.NFData BlueInstanceTerminationOption

instance Core.ToJSON BlueInstanceTerminationOption where
  toJSON :: BlueInstanceTerminationOption -> Value
toJSON BlueInstanceTerminationOption' {Maybe Int
Maybe InstanceAction
terminationWaitTimeInMinutes :: Maybe Int
action :: Maybe InstanceAction
$sel:terminationWaitTimeInMinutes:BlueInstanceTerminationOption' :: BlueInstanceTerminationOption -> Maybe Int
$sel:action:BlueInstanceTerminationOption' :: BlueInstanceTerminationOption -> Maybe InstanceAction
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"action" Text -> InstanceAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (InstanceAction -> Pair) -> Maybe InstanceAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe InstanceAction
action,
            (Text
"terminationWaitTimeInMinutes" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
terminationWaitTimeInMinutes
          ]
      )