{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ECS.Types.AutoScalingGroupProvider where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ECS.Types.ManagedScaling
import Amazonka.ECS.Types.ManagedTerminationProtection
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. The default is disabled.
    --
    -- When using managed termination protection, managed scaling must also be
    -- used otherwise managed termination protection doesn\'t 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 aren\'t 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
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]
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
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.
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. The default is disabled.
--
-- When using managed termination protection, managed scaling must also be
-- used otherwise managed termination protection doesn\'t 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 aren\'t 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'
    { $sel:managedScaling:AutoScalingGroupProvider' :: Maybe ManagedScaling
managedScaling =
        forall a. Maybe a
Prelude.Nothing,
      $sel:managedTerminationProtection:AutoScalingGroupProvider' :: Maybe ManagedTerminationProtection
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 :: Lens' AutoScalingGroupProvider (Maybe ManagedScaling)
autoScalingGroupProvider_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. The default is disabled.
--
-- When using managed termination protection, managed scaling must also be
-- used otherwise managed termination protection doesn\'t 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 aren\'t protected from termination when the Auto Scaling group
-- scales in.
autoScalingGroupProvider_managedTerminationProtection :: Lens.Lens' AutoScalingGroupProvider (Prelude.Maybe ManagedTerminationProtection)
autoScalingGroupProvider_managedTerminationProtection :: Lens' AutoScalingGroupProvider (Maybe ManagedTerminationProtection)
autoScalingGroupProvider_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 :: Lens' AutoScalingGroupProvider Text
autoScalingGroupProvider_autoScalingGroupArn = 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 Data.FromJSON AutoScalingGroupProvider where
  parseJSON :: Value -> Parser AutoScalingGroupProvider
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AutoScalingGroupProvider"
      ( \Object
x ->
          Maybe ManagedScaling
-> Maybe ManagedTerminationProtection
-> Text
-> AutoScalingGroupProvider
AutoScalingGroupProvider'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"managedScaling")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"managedTerminationProtection")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"autoScalingGroupArn")
      )

instance Prelude.Hashable AutoScalingGroupProvider where
  hashWithSalt :: Int -> AutoScalingGroupProvider -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ManagedScaling
managedScaling
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ManagedTerminationProtection
managedTerminationProtection
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
autoScalingGroupArn

instance Prelude.NFData AutoScalingGroupProvider where
  rnf :: AutoScalingGroupProvider -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ManagedScaling
managedScaling
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ManagedTerminationProtection
managedTerminationProtection
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
autoScalingGroupArn

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"managedScaling" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ManagedScaling
managedScaling,
            (Key
"managedTerminationProtection" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ManagedTerminationProtection
managedTerminationProtection,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"autoScalingGroupArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
autoScalingGroupArn)
          ]
      )