{-# 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.AutoScaling.Types.LifecycleHookSpecification
-- 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.AutoScaling.Types.LifecycleHookSpecification where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes information used to specify a lifecycle hook for an Auto
-- Scaling group.
--
-- A lifecycle hook tells Amazon EC2 Auto Scaling to perform an action on
-- an instance when the instance launches (before it is put into service)
-- or as the instance terminates (before it is fully terminated).
--
-- This step is a part of the procedure for creating a lifecycle hook for
-- an Auto Scaling group:
--
-- 1.  (Optional) Create a Lambda function and a rule that allows
--     CloudWatch Events to invoke your Lambda function when Amazon EC2
--     Auto Scaling launches or terminates instances.
--
-- 2.  (Optional) Create a notification target and an IAM role. The target
--     can be either an Amazon SQS queue or an Amazon SNS topic. The role
--     allows Amazon EC2 Auto Scaling to publish lifecycle notifications to
--     the target.
--
-- 3.  __Create the lifecycle hook. Specify whether the hook is used when
--     the instances launch or terminate.__
--
-- 4.  If you need more time, record the lifecycle action heartbeat to keep
--     the instance in a pending state.
--
-- 5.  If you finish before the timeout period ends, complete the lifecycle
--     action.
--
-- For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html Amazon EC2 Auto Scaling lifecycle hooks>
-- in the /Amazon EC2 Auto Scaling User Guide/.
--
-- /See:/ 'newLifecycleHookSpecification' smart constructor.
data LifecycleHookSpecification = LifecycleHookSpecification'
  { -- | Defines the action the Auto Scaling group should take when the lifecycle
    -- hook timeout elapses or if an unexpected failure occurs. The valid
    -- values are @CONTINUE@ and @ABANDON@. The default value is @ABANDON@.
    LifecycleHookSpecification -> Maybe Text
defaultResult :: Prelude.Maybe Prelude.Text,
    -- | The maximum time, in seconds, that can elapse before the lifecycle hook
    -- times out.
    --
    -- If the lifecycle hook times out, Amazon EC2 Auto Scaling performs the
    -- action that you specified in the @DefaultResult@ parameter. You can
    -- prevent the lifecycle hook from timing out by calling
    -- RecordLifecycleActionHeartbeat.
    LifecycleHookSpecification -> Maybe Int
heartbeatTimeout :: Prelude.Maybe Prelude.Int,
    -- | Additional information that you want to include any time Amazon EC2 Auto
    -- Scaling sends a message to the notification target.
    LifecycleHookSpecification -> Maybe Text
notificationMetadata :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the target that Amazon EC2 Auto Scaling sends notifications
    -- to when an instance is in the transition state for the lifecycle hook.
    -- The notification target can be either an SQS queue or an SNS topic.
    LifecycleHookSpecification -> Maybe Text
notificationTargetARN :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the IAM role that allows the Auto Scaling group to publish to
    -- the specified notification target, for example, an Amazon SNS topic or
    -- an Amazon SQS queue.
    LifecycleHookSpecification -> Maybe Text
roleARN :: Prelude.Maybe Prelude.Text,
    -- | The name of the lifecycle hook.
    LifecycleHookSpecification -> Text
lifecycleHookName :: Prelude.Text,
    -- | The state of the EC2 instance to which you want to attach the lifecycle
    -- hook. The valid values are:
    --
    -- -   autoscaling:EC2_INSTANCE_LAUNCHING
    --
    -- -   autoscaling:EC2_INSTANCE_TERMINATING
    LifecycleHookSpecification -> Text
lifecycleTransition :: Prelude.Text
  }
  deriving (LifecycleHookSpecification -> LifecycleHookSpecification -> Bool
(LifecycleHookSpecification -> LifecycleHookSpecification -> Bool)
-> (LifecycleHookSpecification
    -> LifecycleHookSpecification -> Bool)
-> Eq LifecycleHookSpecification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LifecycleHookSpecification -> LifecycleHookSpecification -> Bool
$c/= :: LifecycleHookSpecification -> LifecycleHookSpecification -> Bool
== :: LifecycleHookSpecification -> LifecycleHookSpecification -> Bool
$c== :: LifecycleHookSpecification -> LifecycleHookSpecification -> Bool
Prelude.Eq, ReadPrec [LifecycleHookSpecification]
ReadPrec LifecycleHookSpecification
Int -> ReadS LifecycleHookSpecification
ReadS [LifecycleHookSpecification]
(Int -> ReadS LifecycleHookSpecification)
-> ReadS [LifecycleHookSpecification]
-> ReadPrec LifecycleHookSpecification
-> ReadPrec [LifecycleHookSpecification]
-> Read LifecycleHookSpecification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LifecycleHookSpecification]
$creadListPrec :: ReadPrec [LifecycleHookSpecification]
readPrec :: ReadPrec LifecycleHookSpecification
$creadPrec :: ReadPrec LifecycleHookSpecification
readList :: ReadS [LifecycleHookSpecification]
$creadList :: ReadS [LifecycleHookSpecification]
readsPrec :: Int -> ReadS LifecycleHookSpecification
$creadsPrec :: Int -> ReadS LifecycleHookSpecification
Prelude.Read, Int -> LifecycleHookSpecification -> ShowS
[LifecycleHookSpecification] -> ShowS
LifecycleHookSpecification -> String
(Int -> LifecycleHookSpecification -> ShowS)
-> (LifecycleHookSpecification -> String)
-> ([LifecycleHookSpecification] -> ShowS)
-> Show LifecycleHookSpecification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LifecycleHookSpecification] -> ShowS
$cshowList :: [LifecycleHookSpecification] -> ShowS
show :: LifecycleHookSpecification -> String
$cshow :: LifecycleHookSpecification -> String
showsPrec :: Int -> LifecycleHookSpecification -> ShowS
$cshowsPrec :: Int -> LifecycleHookSpecification -> ShowS
Prelude.Show, (forall x.
 LifecycleHookSpecification -> Rep LifecycleHookSpecification x)
-> (forall x.
    Rep LifecycleHookSpecification x -> LifecycleHookSpecification)
-> Generic LifecycleHookSpecification
forall x.
Rep LifecycleHookSpecification x -> LifecycleHookSpecification
forall x.
LifecycleHookSpecification -> Rep LifecycleHookSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep LifecycleHookSpecification x -> LifecycleHookSpecification
$cfrom :: forall x.
LifecycleHookSpecification -> Rep LifecycleHookSpecification x
Prelude.Generic)

-- |
-- Create a value of 'LifecycleHookSpecification' 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:
--
-- 'defaultResult', 'lifecycleHookSpecification_defaultResult' - Defines the action the Auto Scaling group should take when the lifecycle
-- hook timeout elapses or if an unexpected failure occurs. The valid
-- values are @CONTINUE@ and @ABANDON@. The default value is @ABANDON@.
--
-- 'heartbeatTimeout', 'lifecycleHookSpecification_heartbeatTimeout' - The maximum time, in seconds, that can elapse before the lifecycle hook
-- times out.
--
-- If the lifecycle hook times out, Amazon EC2 Auto Scaling performs the
-- action that you specified in the @DefaultResult@ parameter. You can
-- prevent the lifecycle hook from timing out by calling
-- RecordLifecycleActionHeartbeat.
--
-- 'notificationMetadata', 'lifecycleHookSpecification_notificationMetadata' - Additional information that you want to include any time Amazon EC2 Auto
-- Scaling sends a message to the notification target.
--
-- 'notificationTargetARN', 'lifecycleHookSpecification_notificationTargetARN' - The ARN of the target that Amazon EC2 Auto Scaling sends notifications
-- to when an instance is in the transition state for the lifecycle hook.
-- The notification target can be either an SQS queue or an SNS topic.
--
-- 'roleARN', 'lifecycleHookSpecification_roleARN' - The ARN of the IAM role that allows the Auto Scaling group to publish to
-- the specified notification target, for example, an Amazon SNS topic or
-- an Amazon SQS queue.
--
-- 'lifecycleHookName', 'lifecycleHookSpecification_lifecycleHookName' - The name of the lifecycle hook.
--
-- 'lifecycleTransition', 'lifecycleHookSpecification_lifecycleTransition' - The state of the EC2 instance to which you want to attach the lifecycle
-- hook. The valid values are:
--
-- -   autoscaling:EC2_INSTANCE_LAUNCHING
--
-- -   autoscaling:EC2_INSTANCE_TERMINATING
newLifecycleHookSpecification ::
  -- | 'lifecycleHookName'
  Prelude.Text ->
  -- | 'lifecycleTransition'
  Prelude.Text ->
  LifecycleHookSpecification
newLifecycleHookSpecification :: Text -> Text -> LifecycleHookSpecification
newLifecycleHookSpecification
  Text
pLifecycleHookName_
  Text
pLifecycleTransition_ =
    LifecycleHookSpecification' :: Maybe Text
-> Maybe Int
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> Text
-> LifecycleHookSpecification
LifecycleHookSpecification'
      { $sel:defaultResult:LifecycleHookSpecification' :: Maybe Text
defaultResult =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:heartbeatTimeout:LifecycleHookSpecification' :: Maybe Int
heartbeatTimeout = Maybe Int
forall a. Maybe a
Prelude.Nothing,
        $sel:notificationMetadata:LifecycleHookSpecification' :: Maybe Text
notificationMetadata = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:notificationTargetARN:LifecycleHookSpecification' :: Maybe Text
notificationTargetARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:roleARN:LifecycleHookSpecification' :: Maybe Text
roleARN = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:lifecycleHookName:LifecycleHookSpecification' :: Text
lifecycleHookName = Text
pLifecycleHookName_,
        $sel:lifecycleTransition:LifecycleHookSpecification' :: Text
lifecycleTransition = Text
pLifecycleTransition_
      }

-- | Defines the action the Auto Scaling group should take when the lifecycle
-- hook timeout elapses or if an unexpected failure occurs. The valid
-- values are @CONTINUE@ and @ABANDON@. The default value is @ABANDON@.
lifecycleHookSpecification_defaultResult :: Lens.Lens' LifecycleHookSpecification (Prelude.Maybe Prelude.Text)
lifecycleHookSpecification_defaultResult :: (Maybe Text -> f (Maybe Text))
-> LifecycleHookSpecification -> f LifecycleHookSpecification
lifecycleHookSpecification_defaultResult = (LifecycleHookSpecification -> Maybe Text)
-> (LifecycleHookSpecification
    -> Maybe Text -> LifecycleHookSpecification)
-> Lens
     LifecycleHookSpecification
     LifecycleHookSpecification
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleHookSpecification' {Maybe Text
defaultResult :: Maybe Text
$sel:defaultResult:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
defaultResult} -> Maybe Text
defaultResult) (\s :: LifecycleHookSpecification
s@LifecycleHookSpecification' {} Maybe Text
a -> LifecycleHookSpecification
s {$sel:defaultResult:LifecycleHookSpecification' :: Maybe Text
defaultResult = Maybe Text
a} :: LifecycleHookSpecification)

-- | The maximum time, in seconds, that can elapse before the lifecycle hook
-- times out.
--
-- If the lifecycle hook times out, Amazon EC2 Auto Scaling performs the
-- action that you specified in the @DefaultResult@ parameter. You can
-- prevent the lifecycle hook from timing out by calling
-- RecordLifecycleActionHeartbeat.
lifecycleHookSpecification_heartbeatTimeout :: Lens.Lens' LifecycleHookSpecification (Prelude.Maybe Prelude.Int)
lifecycleHookSpecification_heartbeatTimeout :: (Maybe Int -> f (Maybe Int))
-> LifecycleHookSpecification -> f LifecycleHookSpecification
lifecycleHookSpecification_heartbeatTimeout = (LifecycleHookSpecification -> Maybe Int)
-> (LifecycleHookSpecification
    -> Maybe Int -> LifecycleHookSpecification)
-> Lens
     LifecycleHookSpecification
     LifecycleHookSpecification
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleHookSpecification' {Maybe Int
heartbeatTimeout :: Maybe Int
$sel:heartbeatTimeout:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Int
heartbeatTimeout} -> Maybe Int
heartbeatTimeout) (\s :: LifecycleHookSpecification
s@LifecycleHookSpecification' {} Maybe Int
a -> LifecycleHookSpecification
s {$sel:heartbeatTimeout:LifecycleHookSpecification' :: Maybe Int
heartbeatTimeout = Maybe Int
a} :: LifecycleHookSpecification)

-- | Additional information that you want to include any time Amazon EC2 Auto
-- Scaling sends a message to the notification target.
lifecycleHookSpecification_notificationMetadata :: Lens.Lens' LifecycleHookSpecification (Prelude.Maybe Prelude.Text)
lifecycleHookSpecification_notificationMetadata :: (Maybe Text -> f (Maybe Text))
-> LifecycleHookSpecification -> f LifecycleHookSpecification
lifecycleHookSpecification_notificationMetadata = (LifecycleHookSpecification -> Maybe Text)
-> (LifecycleHookSpecification
    -> Maybe Text -> LifecycleHookSpecification)
-> Lens
     LifecycleHookSpecification
     LifecycleHookSpecification
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleHookSpecification' {Maybe Text
notificationMetadata :: Maybe Text
$sel:notificationMetadata:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
notificationMetadata} -> Maybe Text
notificationMetadata) (\s :: LifecycleHookSpecification
s@LifecycleHookSpecification' {} Maybe Text
a -> LifecycleHookSpecification
s {$sel:notificationMetadata:LifecycleHookSpecification' :: Maybe Text
notificationMetadata = Maybe Text
a} :: LifecycleHookSpecification)

-- | The ARN of the target that Amazon EC2 Auto Scaling sends notifications
-- to when an instance is in the transition state for the lifecycle hook.
-- The notification target can be either an SQS queue or an SNS topic.
lifecycleHookSpecification_notificationTargetARN :: Lens.Lens' LifecycleHookSpecification (Prelude.Maybe Prelude.Text)
lifecycleHookSpecification_notificationTargetARN :: (Maybe Text -> f (Maybe Text))
-> LifecycleHookSpecification -> f LifecycleHookSpecification
lifecycleHookSpecification_notificationTargetARN = (LifecycleHookSpecification -> Maybe Text)
-> (LifecycleHookSpecification
    -> Maybe Text -> LifecycleHookSpecification)
-> Lens
     LifecycleHookSpecification
     LifecycleHookSpecification
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleHookSpecification' {Maybe Text
notificationTargetARN :: Maybe Text
$sel:notificationTargetARN:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
notificationTargetARN} -> Maybe Text
notificationTargetARN) (\s :: LifecycleHookSpecification
s@LifecycleHookSpecification' {} Maybe Text
a -> LifecycleHookSpecification
s {$sel:notificationTargetARN:LifecycleHookSpecification' :: Maybe Text
notificationTargetARN = Maybe Text
a} :: LifecycleHookSpecification)

-- | The ARN of the IAM role that allows the Auto Scaling group to publish to
-- the specified notification target, for example, an Amazon SNS topic or
-- an Amazon SQS queue.
lifecycleHookSpecification_roleARN :: Lens.Lens' LifecycleHookSpecification (Prelude.Maybe Prelude.Text)
lifecycleHookSpecification_roleARN :: (Maybe Text -> f (Maybe Text))
-> LifecycleHookSpecification -> f LifecycleHookSpecification
lifecycleHookSpecification_roleARN = (LifecycleHookSpecification -> Maybe Text)
-> (LifecycleHookSpecification
    -> Maybe Text -> LifecycleHookSpecification)
-> Lens
     LifecycleHookSpecification
     LifecycleHookSpecification
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleHookSpecification' {Maybe Text
roleARN :: Maybe Text
$sel:roleARN:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
roleARN} -> Maybe Text
roleARN) (\s :: LifecycleHookSpecification
s@LifecycleHookSpecification' {} Maybe Text
a -> LifecycleHookSpecification
s {$sel:roleARN:LifecycleHookSpecification' :: Maybe Text
roleARN = Maybe Text
a} :: LifecycleHookSpecification)

-- | The name of the lifecycle hook.
lifecycleHookSpecification_lifecycleHookName :: Lens.Lens' LifecycleHookSpecification Prelude.Text
lifecycleHookSpecification_lifecycleHookName :: (Text -> f Text)
-> LifecycleHookSpecification -> f LifecycleHookSpecification
lifecycleHookSpecification_lifecycleHookName = (LifecycleHookSpecification -> Text)
-> (LifecycleHookSpecification
    -> Text -> LifecycleHookSpecification)
-> Lens
     LifecycleHookSpecification LifecycleHookSpecification Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleHookSpecification' {Text
lifecycleHookName :: Text
$sel:lifecycleHookName:LifecycleHookSpecification' :: LifecycleHookSpecification -> Text
lifecycleHookName} -> Text
lifecycleHookName) (\s :: LifecycleHookSpecification
s@LifecycleHookSpecification' {} Text
a -> LifecycleHookSpecification
s {$sel:lifecycleHookName:LifecycleHookSpecification' :: Text
lifecycleHookName = Text
a} :: LifecycleHookSpecification)

-- | The state of the EC2 instance to which you want to attach the lifecycle
-- hook. The valid values are:
--
-- -   autoscaling:EC2_INSTANCE_LAUNCHING
--
-- -   autoscaling:EC2_INSTANCE_TERMINATING
lifecycleHookSpecification_lifecycleTransition :: Lens.Lens' LifecycleHookSpecification Prelude.Text
lifecycleHookSpecification_lifecycleTransition :: (Text -> f Text)
-> LifecycleHookSpecification -> f LifecycleHookSpecification
lifecycleHookSpecification_lifecycleTransition = (LifecycleHookSpecification -> Text)
-> (LifecycleHookSpecification
    -> Text -> LifecycleHookSpecification)
-> Lens
     LifecycleHookSpecification LifecycleHookSpecification Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleHookSpecification' {Text
lifecycleTransition :: Text
$sel:lifecycleTransition:LifecycleHookSpecification' :: LifecycleHookSpecification -> Text
lifecycleTransition} -> Text
lifecycleTransition) (\s :: LifecycleHookSpecification
s@LifecycleHookSpecification' {} Text
a -> LifecycleHookSpecification
s {$sel:lifecycleTransition:LifecycleHookSpecification' :: Text
lifecycleTransition = Text
a} :: LifecycleHookSpecification)

instance Prelude.Hashable LifecycleHookSpecification

instance Prelude.NFData LifecycleHookSpecification

instance Core.ToQuery LifecycleHookSpecification where
  toQuery :: LifecycleHookSpecification -> QueryString
toQuery LifecycleHookSpecification' {Maybe Int
Maybe Text
Text
lifecycleTransition :: Text
lifecycleHookName :: Text
roleARN :: Maybe Text
notificationTargetARN :: Maybe Text
notificationMetadata :: Maybe Text
heartbeatTimeout :: Maybe Int
defaultResult :: Maybe Text
$sel:lifecycleTransition:LifecycleHookSpecification' :: LifecycleHookSpecification -> Text
$sel:lifecycleHookName:LifecycleHookSpecification' :: LifecycleHookSpecification -> Text
$sel:roleARN:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
$sel:notificationTargetARN:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
$sel:notificationMetadata:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
$sel:heartbeatTimeout:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Int
$sel:defaultResult:LifecycleHookSpecification' :: LifecycleHookSpecification -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"DefaultResult" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
defaultResult,
        ByteString
"HeartbeatTimeout" ByteString -> Maybe Int -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Int
heartbeatTimeout,
        ByteString
"NotificationMetadata" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
notificationMetadata,
        ByteString
"NotificationTargetARN"
          ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
notificationTargetARN,
        ByteString
"RoleARN" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
roleARN,
        ByteString
"LifecycleHookName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
lifecycleHookName,
        ByteString
"LifecycleTransition" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
lifecycleTransition
      ]