{-# 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.ECS.Types.AutoScalingGroupProvider
-- 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.ECS.Types.AutoScalingGroupProvider where

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.ManagedScaling
import Amazonka.ECS.Types.ManagedTerminationProtection
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The details of the Auto Scaling group for the capacity provider.
--
-- /See:/ 'newAutoScalingGroupProvider' smart constructor.
data AutoScalingGroupProvider = AutoScalingGroupProvider'
  { -- | The managed scaling settings for the Auto Scaling group capacity
    -- provider.
    AutoScalingGroupProvider -> Maybe ManagedScaling
managedScaling :: Prelude.Maybe ManagedScaling,
    -- | The managed termination protection setting to use for the Auto Scaling
    -- group capacity provider. This determines whether the Auto Scaling group
    -- has managed termination protection.
    --
    -- When using managed termination protection, managed scaling must also be
    -- used otherwise managed termination protection will not work.
    --
    -- When managed termination protection is enabled, Amazon ECS prevents the
    -- Amazon EC2 instances in an Auto Scaling group that contain tasks from
    -- being terminated during a scale-in action. The Auto Scaling group and
    -- each instance in the Auto Scaling group must have instance protection
    -- from scale-in actions enabled as well. For more information, see
    -- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-termination.html#instance-protection Instance Protection>
    -- in the /Auto Scaling User Guide/.
    --
    -- When managed termination protection is disabled, your Amazon EC2
    -- instances are not protected from termination when the Auto Scaling group
    -- scales in.
    AutoScalingGroupProvider -> Maybe ManagedTerminationProtection
managedTerminationProtection :: Prelude.Maybe ManagedTerminationProtection,
    -- | The Amazon Resource Name (ARN) that identifies the Auto Scaling group.
    AutoScalingGroupProvider -> Text
autoScalingGroupArn :: Prelude.Text
  }
  deriving (AutoScalingGroupProvider -> AutoScalingGroupProvider -> Bool
(AutoScalingGroupProvider -> AutoScalingGroupProvider -> Bool)
-> (AutoScalingGroupProvider -> AutoScalingGroupProvider -> Bool)
-> Eq AutoScalingGroupProvider
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutoScalingGroupProvider -> AutoScalingGroupProvider -> Bool
$c/= :: AutoScalingGroupProvider -> AutoScalingGroupProvider -> Bool
== :: AutoScalingGroupProvider -> AutoScalingGroupProvider -> Bool
$c== :: AutoScalingGroupProvider -> AutoScalingGroupProvider -> Bool
Prelude.Eq, ReadPrec [AutoScalingGroupProvider]
ReadPrec AutoScalingGroupProvider
Int -> ReadS AutoScalingGroupProvider
ReadS [AutoScalingGroupProvider]
(Int -> ReadS AutoScalingGroupProvider)
-> ReadS [AutoScalingGroupProvider]
-> ReadPrec AutoScalingGroupProvider
-> ReadPrec [AutoScalingGroupProvider]
-> Read AutoScalingGroupProvider
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AutoScalingGroupProvider]
$creadListPrec :: ReadPrec [AutoScalingGroupProvider]
readPrec :: ReadPrec AutoScalingGroupProvider
$creadPrec :: ReadPrec AutoScalingGroupProvider
readList :: ReadS [AutoScalingGroupProvider]
$creadList :: ReadS [AutoScalingGroupProvider]
readsPrec :: Int -> ReadS AutoScalingGroupProvider
$creadsPrec :: Int -> ReadS AutoScalingGroupProvider
Prelude.Read, Int -> AutoScalingGroupProvider -> ShowS
[AutoScalingGroupProvider] -> ShowS
AutoScalingGroupProvider -> String
(Int -> AutoScalingGroupProvider -> ShowS)
-> (AutoScalingGroupProvider -> String)
-> ([AutoScalingGroupProvider] -> ShowS)
-> Show AutoScalingGroupProvider
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutoScalingGroupProvider] -> ShowS
$cshowList :: [AutoScalingGroupProvider] -> ShowS
show :: AutoScalingGroupProvider -> String
$cshow :: AutoScalingGroupProvider -> String
showsPrec :: Int -> AutoScalingGroupProvider -> ShowS
$cshowsPrec :: Int -> AutoScalingGroupProvider -> ShowS
Prelude.Show, (forall x.
 AutoScalingGroupProvider -> Rep AutoScalingGroupProvider x)
-> (forall x.
    Rep AutoScalingGroupProvider x -> AutoScalingGroupProvider)
-> Generic AutoScalingGroupProvider
forall x.
Rep AutoScalingGroupProvider x -> AutoScalingGroupProvider
forall x.
AutoScalingGroupProvider -> Rep AutoScalingGroupProvider x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AutoScalingGroupProvider x -> AutoScalingGroupProvider
$cfrom :: forall x.
AutoScalingGroupProvider -> Rep AutoScalingGroupProvider x
Prelude.Generic)

-- |
-- Create a value of 'AutoScalingGroupProvider' 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:
--
-- 'managedScaling', 'autoScalingGroupProvider_managedScaling' - The managed scaling settings for the Auto Scaling group capacity
-- provider.
--
-- 'managedTerminationProtection', 'autoScalingGroupProvider_managedTerminationProtection' - The managed termination protection setting to use for the Auto Scaling
-- group capacity provider. This determines whether the Auto Scaling group
-- has managed termination protection.
--
-- When using managed termination protection, managed scaling must also be
-- used otherwise managed termination protection will not work.
--
-- When managed termination protection is enabled, Amazon ECS prevents the
-- Amazon EC2 instances in an Auto Scaling group that contain tasks from
-- being terminated during a scale-in action. The Auto Scaling group and
-- each instance in the Auto Scaling group must have instance protection
-- from scale-in actions enabled as well. For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-termination.html#instance-protection Instance Protection>
-- in the /Auto Scaling User Guide/.
--
-- When managed termination protection is disabled, your Amazon EC2
-- instances are not protected from termination when the Auto Scaling group
-- scales in.
--
-- 'autoScalingGroupArn', 'autoScalingGroupProvider_autoScalingGroupArn' - The Amazon Resource Name (ARN) that identifies the Auto Scaling group.
newAutoScalingGroupProvider ::
  -- | 'autoScalingGroupArn'
  Prelude.Text ->
  AutoScalingGroupProvider
newAutoScalingGroupProvider :: Text -> AutoScalingGroupProvider
newAutoScalingGroupProvider Text
pAutoScalingGroupArn_ =
  AutoScalingGroupProvider' :: Maybe ManagedScaling
-> Maybe ManagedTerminationProtection
-> Text
-> AutoScalingGroupProvider
AutoScalingGroupProvider'
    { $sel:managedScaling:AutoScalingGroupProvider' :: Maybe ManagedScaling
managedScaling =
        Maybe ManagedScaling
forall a. Maybe a
Prelude.Nothing,
      $sel:managedTerminationProtection:AutoScalingGroupProvider' :: Maybe ManagedTerminationProtection
managedTerminationProtection = Maybe ManagedTerminationProtection
forall a. Maybe a
Prelude.Nothing,
      $sel:autoScalingGroupArn:AutoScalingGroupProvider' :: Text
autoScalingGroupArn = Text
pAutoScalingGroupArn_
    }

-- | The managed scaling settings for the Auto Scaling group capacity
-- provider.
autoScalingGroupProvider_managedScaling :: Lens.Lens' AutoScalingGroupProvider (Prelude.Maybe ManagedScaling)
autoScalingGroupProvider_managedScaling :: (Maybe ManagedScaling -> f (Maybe ManagedScaling))
-> AutoScalingGroupProvider -> f AutoScalingGroupProvider
autoScalingGroupProvider_managedScaling = (AutoScalingGroupProvider -> Maybe ManagedScaling)
-> (AutoScalingGroupProvider
    -> Maybe ManagedScaling -> AutoScalingGroupProvider)
-> Lens
     AutoScalingGroupProvider
     AutoScalingGroupProvider
     (Maybe ManagedScaling)
     (Maybe ManagedScaling)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoScalingGroupProvider' {Maybe ManagedScaling
managedScaling :: Maybe ManagedScaling
$sel:managedScaling:AutoScalingGroupProvider' :: AutoScalingGroupProvider -> Maybe ManagedScaling
managedScaling} -> Maybe ManagedScaling
managedScaling) (\s :: AutoScalingGroupProvider
s@AutoScalingGroupProvider' {} Maybe ManagedScaling
a -> AutoScalingGroupProvider
s {$sel:managedScaling:AutoScalingGroupProvider' :: Maybe ManagedScaling
managedScaling = Maybe ManagedScaling
a} :: AutoScalingGroupProvider)

-- | The managed termination protection setting to use for the Auto Scaling
-- group capacity provider. This determines whether the Auto Scaling group
-- has managed termination protection.
--
-- When using managed termination protection, managed scaling must also be
-- used otherwise managed termination protection will not work.
--
-- When managed termination protection is enabled, Amazon ECS prevents the
-- Amazon EC2 instances in an Auto Scaling group that contain tasks from
-- being terminated during a scale-in action. The Auto Scaling group and
-- each instance in the Auto Scaling group must have instance protection
-- from scale-in actions enabled as well. For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-termination.html#instance-protection Instance Protection>
-- in the /Auto Scaling User Guide/.
--
-- When managed termination protection is disabled, your Amazon EC2
-- instances are not protected from termination when the Auto Scaling group
-- scales in.
autoScalingGroupProvider_managedTerminationProtection :: Lens.Lens' AutoScalingGroupProvider (Prelude.Maybe ManagedTerminationProtection)
autoScalingGroupProvider_managedTerminationProtection :: (Maybe ManagedTerminationProtection
 -> f (Maybe ManagedTerminationProtection))
-> AutoScalingGroupProvider -> f AutoScalingGroupProvider
autoScalingGroupProvider_managedTerminationProtection = (AutoScalingGroupProvider -> Maybe ManagedTerminationProtection)
-> (AutoScalingGroupProvider
    -> Maybe ManagedTerminationProtection -> AutoScalingGroupProvider)
-> Lens
     AutoScalingGroupProvider
     AutoScalingGroupProvider
     (Maybe ManagedTerminationProtection)
     (Maybe ManagedTerminationProtection)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoScalingGroupProvider' {Maybe ManagedTerminationProtection
managedTerminationProtection :: Maybe ManagedTerminationProtection
$sel:managedTerminationProtection:AutoScalingGroupProvider' :: AutoScalingGroupProvider -> Maybe ManagedTerminationProtection
managedTerminationProtection} -> Maybe ManagedTerminationProtection
managedTerminationProtection) (\s :: AutoScalingGroupProvider
s@AutoScalingGroupProvider' {} Maybe ManagedTerminationProtection
a -> AutoScalingGroupProvider
s {$sel:managedTerminationProtection:AutoScalingGroupProvider' :: Maybe ManagedTerminationProtection
managedTerminationProtection = Maybe ManagedTerminationProtection
a} :: AutoScalingGroupProvider)

-- | The Amazon Resource Name (ARN) that identifies the Auto Scaling group.
autoScalingGroupProvider_autoScalingGroupArn :: Lens.Lens' AutoScalingGroupProvider Prelude.Text
autoScalingGroupProvider_autoScalingGroupArn :: (Text -> f Text)
-> AutoScalingGroupProvider -> f AutoScalingGroupProvider
autoScalingGroupProvider_autoScalingGroupArn = (AutoScalingGroupProvider -> Text)
-> (AutoScalingGroupProvider -> Text -> AutoScalingGroupProvider)
-> Lens AutoScalingGroupProvider AutoScalingGroupProvider Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoScalingGroupProvider' {Text
autoScalingGroupArn :: Text
$sel:autoScalingGroupArn:AutoScalingGroupProvider' :: AutoScalingGroupProvider -> Text
autoScalingGroupArn} -> Text
autoScalingGroupArn) (\s :: AutoScalingGroupProvider
s@AutoScalingGroupProvider' {} Text
a -> AutoScalingGroupProvider
s {$sel:autoScalingGroupArn:AutoScalingGroupProvider' :: Text
autoScalingGroupArn = Text
a} :: AutoScalingGroupProvider)

instance Core.FromJSON AutoScalingGroupProvider where
  parseJSON :: Value -> Parser AutoScalingGroupProvider
parseJSON =
    String
-> (Object -> Parser AutoScalingGroupProvider)
-> Value
-> Parser AutoScalingGroupProvider
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AutoScalingGroupProvider"
      ( \Object
x ->
          Maybe ManagedScaling
-> Maybe ManagedTerminationProtection
-> Text
-> AutoScalingGroupProvider
AutoScalingGroupProvider'
            (Maybe ManagedScaling
 -> Maybe ManagedTerminationProtection
 -> Text
 -> AutoScalingGroupProvider)
-> Parser (Maybe ManagedScaling)
-> Parser
     (Maybe ManagedTerminationProtection
      -> Text -> AutoScalingGroupProvider)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ManagedScaling)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"managedScaling")
            Parser
  (Maybe ManagedTerminationProtection
   -> Text -> AutoScalingGroupProvider)
-> Parser (Maybe ManagedTerminationProtection)
-> Parser (Text -> AutoScalingGroupProvider)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ManagedTerminationProtection)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"managedTerminationProtection")
            Parser (Text -> AutoScalingGroupProvider)
-> Parser Text -> Parser AutoScalingGroupProvider
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"autoScalingGroupArn")
      )

instance Prelude.Hashable AutoScalingGroupProvider

instance Prelude.NFData AutoScalingGroupProvider

instance Core.ToJSON AutoScalingGroupProvider where
  toJSON :: AutoScalingGroupProvider -> Value
toJSON AutoScalingGroupProvider' {Maybe ManagedScaling
Maybe ManagedTerminationProtection
Text
autoScalingGroupArn :: Text
managedTerminationProtection :: Maybe ManagedTerminationProtection
managedScaling :: Maybe ManagedScaling
$sel:autoScalingGroupArn:AutoScalingGroupProvider' :: AutoScalingGroupProvider -> Text
$sel:managedTerminationProtection:AutoScalingGroupProvider' :: AutoScalingGroupProvider -> Maybe ManagedTerminationProtection
$sel:managedScaling:AutoScalingGroupProvider' :: AutoScalingGroupProvider -> Maybe ManagedScaling
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"managedScaling" Text -> ManagedScaling -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ManagedScaling -> Pair) -> Maybe ManagedScaling -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ManagedScaling
managedScaling,
            (Text
"managedTerminationProtection" Text -> ManagedTerminationProtection -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ManagedTerminationProtection -> Pair)
-> Maybe ManagedTerminationProtection -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ManagedTerminationProtection
managedTerminationProtection,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"autoScalingGroupArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
autoScalingGroupArn)
          ]
      )