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

import Amazonka.AutoScaling.Types.LaunchTemplateSpecification
import Amazonka.AutoScaling.Types.LifecycleState
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Describes an EC2 instance.
--
-- /See:/ 'newInstance' smart constructor.
data Instance = Instance'
  { -- | The instance type of the EC2 instance.
    Instance -> Maybe Text
instanceType :: Prelude.Maybe Prelude.Text,
    -- | The launch configuration associated with the instance.
    Instance -> Maybe Text
launchConfigurationName :: Prelude.Maybe Prelude.Text,
    -- | The launch template for the instance.
    Instance -> Maybe LaunchTemplateSpecification
launchTemplate :: Prelude.Maybe LaunchTemplateSpecification,
    -- | The number of capacity units contributed by the instance based on its
    -- instance type.
    --
    -- Valid Range: Minimum value of 1. Maximum value of 999.
    Instance -> Maybe Text
weightedCapacity :: Prelude.Maybe Prelude.Text,
    -- | The ID of the instance.
    Instance -> Text
instanceId :: Prelude.Text,
    -- | The Availability Zone in which the instance is running.
    Instance -> Text
availabilityZone :: Prelude.Text,
    -- | A description of the current lifecycle state. The @Quarantined@ state is
    -- not used. For information about lifecycle states, see
    -- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroupLifecycle.html Instance lifecycle>
    -- in the /Amazon EC2 Auto Scaling User Guide/.
    Instance -> LifecycleState
lifecycleState :: LifecycleState,
    -- | The last reported health status of the instance. \"Healthy\" means that
    -- the instance is healthy and should remain in service. \"Unhealthy\"
    -- means that the instance is unhealthy and that Amazon EC2 Auto Scaling
    -- should terminate and replace it.
    Instance -> Text
healthStatus :: Prelude.Text,
    -- | Indicates whether the instance is protected from termination by Amazon
    -- EC2 Auto Scaling when scaling in.
    Instance -> Bool
protectedFromScaleIn :: Prelude.Bool
  }
  deriving (Instance -> Instance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Instance -> Instance -> Bool
$c/= :: Instance -> Instance -> Bool
== :: Instance -> Instance -> Bool
$c== :: Instance -> Instance -> Bool
Prelude.Eq, ReadPrec [Instance]
ReadPrec Instance
Int -> ReadS Instance
ReadS [Instance]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Instance]
$creadListPrec :: ReadPrec [Instance]
readPrec :: ReadPrec Instance
$creadPrec :: ReadPrec Instance
readList :: ReadS [Instance]
$creadList :: ReadS [Instance]
readsPrec :: Int -> ReadS Instance
$creadsPrec :: Int -> ReadS Instance
Prelude.Read, Int -> Instance -> ShowS
[Instance] -> ShowS
Instance -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Instance] -> ShowS
$cshowList :: [Instance] -> ShowS
show :: Instance -> String
$cshow :: Instance -> String
showsPrec :: Int -> Instance -> ShowS
$cshowsPrec :: Int -> Instance -> ShowS
Prelude.Show, forall x. Rep Instance x -> Instance
forall x. Instance -> Rep Instance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Instance x -> Instance
$cfrom :: forall x. Instance -> Rep Instance x
Prelude.Generic)

-- |
-- Create a value of 'Instance' 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:
--
-- 'instanceType', 'instance_instanceType' - The instance type of the EC2 instance.
--
-- 'launchConfigurationName', 'instance_launchConfigurationName' - The launch configuration associated with the instance.
--
-- 'launchTemplate', 'instance_launchTemplate' - The launch template for the instance.
--
-- 'weightedCapacity', 'instance_weightedCapacity' - The number of capacity units contributed by the instance based on its
-- instance type.
--
-- Valid Range: Minimum value of 1. Maximum value of 999.
--
-- 'instanceId', 'instance_instanceId' - The ID of the instance.
--
-- 'availabilityZone', 'instance_availabilityZone' - The Availability Zone in which the instance is running.
--
-- 'lifecycleState', 'instance_lifecycleState' - A description of the current lifecycle state. The @Quarantined@ state is
-- not used. For information about lifecycle states, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroupLifecycle.html Instance lifecycle>
-- in the /Amazon EC2 Auto Scaling User Guide/.
--
-- 'healthStatus', 'instance_healthStatus' - The last reported health status of the instance. \"Healthy\" means that
-- the instance is healthy and should remain in service. \"Unhealthy\"
-- means that the instance is unhealthy and that Amazon EC2 Auto Scaling
-- should terminate and replace it.
--
-- 'protectedFromScaleIn', 'instance_protectedFromScaleIn' - Indicates whether the instance is protected from termination by Amazon
-- EC2 Auto Scaling when scaling in.
newInstance ::
  -- | 'instanceId'
  Prelude.Text ->
  -- | 'availabilityZone'
  Prelude.Text ->
  -- | 'lifecycleState'
  LifecycleState ->
  -- | 'healthStatus'
  Prelude.Text ->
  -- | 'protectedFromScaleIn'
  Prelude.Bool ->
  Instance
newInstance :: Text -> Text -> LifecycleState -> Text -> Bool -> Instance
newInstance
  Text
pInstanceId_
  Text
pAvailabilityZone_
  LifecycleState
pLifecycleState_
  Text
pHealthStatus_
  Bool
pProtectedFromScaleIn_ =
    Instance'
      { $sel:instanceType:Instance' :: Maybe Text
instanceType = forall a. Maybe a
Prelude.Nothing,
        $sel:launchConfigurationName:Instance' :: Maybe Text
launchConfigurationName = forall a. Maybe a
Prelude.Nothing,
        $sel:launchTemplate:Instance' :: Maybe LaunchTemplateSpecification
launchTemplate = forall a. Maybe a
Prelude.Nothing,
        $sel:weightedCapacity:Instance' :: Maybe Text
weightedCapacity = forall a. Maybe a
Prelude.Nothing,
        $sel:instanceId:Instance' :: Text
instanceId = Text
pInstanceId_,
        $sel:availabilityZone:Instance' :: Text
availabilityZone = Text
pAvailabilityZone_,
        $sel:lifecycleState:Instance' :: LifecycleState
lifecycleState = LifecycleState
pLifecycleState_,
        $sel:healthStatus:Instance' :: Text
healthStatus = Text
pHealthStatus_,
        $sel:protectedFromScaleIn:Instance' :: Bool
protectedFromScaleIn = Bool
pProtectedFromScaleIn_
      }

-- | The instance type of the EC2 instance.
instance_instanceType :: Lens.Lens' Instance (Prelude.Maybe Prelude.Text)
instance_instanceType :: Lens' Instance (Maybe Text)
instance_instanceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Maybe Text
instanceType :: Maybe Text
$sel:instanceType:Instance' :: Instance -> Maybe Text
instanceType} -> Maybe Text
instanceType) (\s :: Instance
s@Instance' {} Maybe Text
a -> Instance
s {$sel:instanceType:Instance' :: Maybe Text
instanceType = Maybe Text
a} :: Instance)

-- | The launch configuration associated with the instance.
instance_launchConfigurationName :: Lens.Lens' Instance (Prelude.Maybe Prelude.Text)
instance_launchConfigurationName :: Lens' Instance (Maybe Text)
instance_launchConfigurationName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Maybe Text
launchConfigurationName :: Maybe Text
$sel:launchConfigurationName:Instance' :: Instance -> Maybe Text
launchConfigurationName} -> Maybe Text
launchConfigurationName) (\s :: Instance
s@Instance' {} Maybe Text
a -> Instance
s {$sel:launchConfigurationName:Instance' :: Maybe Text
launchConfigurationName = Maybe Text
a} :: Instance)

-- | The launch template for the instance.
instance_launchTemplate :: Lens.Lens' Instance (Prelude.Maybe LaunchTemplateSpecification)
instance_launchTemplate :: Lens' Instance (Maybe LaunchTemplateSpecification)
instance_launchTemplate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Maybe LaunchTemplateSpecification
launchTemplate :: Maybe LaunchTemplateSpecification
$sel:launchTemplate:Instance' :: Instance -> Maybe LaunchTemplateSpecification
launchTemplate} -> Maybe LaunchTemplateSpecification
launchTemplate) (\s :: Instance
s@Instance' {} Maybe LaunchTemplateSpecification
a -> Instance
s {$sel:launchTemplate:Instance' :: Maybe LaunchTemplateSpecification
launchTemplate = Maybe LaunchTemplateSpecification
a} :: Instance)

-- | The number of capacity units contributed by the instance based on its
-- instance type.
--
-- Valid Range: Minimum value of 1. Maximum value of 999.
instance_weightedCapacity :: Lens.Lens' Instance (Prelude.Maybe Prelude.Text)
instance_weightedCapacity :: Lens' Instance (Maybe Text)
instance_weightedCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Maybe Text
weightedCapacity :: Maybe Text
$sel:weightedCapacity:Instance' :: Instance -> Maybe Text
weightedCapacity} -> Maybe Text
weightedCapacity) (\s :: Instance
s@Instance' {} Maybe Text
a -> Instance
s {$sel:weightedCapacity:Instance' :: Maybe Text
weightedCapacity = Maybe Text
a} :: Instance)

-- | The ID of the instance.
instance_instanceId :: Lens.Lens' Instance Prelude.Text
instance_instanceId :: Lens' Instance Text
instance_instanceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Text
instanceId :: Text
$sel:instanceId:Instance' :: Instance -> Text
instanceId} -> Text
instanceId) (\s :: Instance
s@Instance' {} Text
a -> Instance
s {$sel:instanceId:Instance' :: Text
instanceId = Text
a} :: Instance)

-- | The Availability Zone in which the instance is running.
instance_availabilityZone :: Lens.Lens' Instance Prelude.Text
instance_availabilityZone :: Lens' Instance Text
instance_availabilityZone = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Text
availabilityZone :: Text
$sel:availabilityZone:Instance' :: Instance -> Text
availabilityZone} -> Text
availabilityZone) (\s :: Instance
s@Instance' {} Text
a -> Instance
s {$sel:availabilityZone:Instance' :: Text
availabilityZone = Text
a} :: Instance)

-- | A description of the current lifecycle state. The @Quarantined@ state is
-- not used. For information about lifecycle states, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroupLifecycle.html Instance lifecycle>
-- in the /Amazon EC2 Auto Scaling User Guide/.
instance_lifecycleState :: Lens.Lens' Instance LifecycleState
instance_lifecycleState :: Lens' Instance LifecycleState
instance_lifecycleState = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {LifecycleState
lifecycleState :: LifecycleState
$sel:lifecycleState:Instance' :: Instance -> LifecycleState
lifecycleState} -> LifecycleState
lifecycleState) (\s :: Instance
s@Instance' {} LifecycleState
a -> Instance
s {$sel:lifecycleState:Instance' :: LifecycleState
lifecycleState = LifecycleState
a} :: Instance)

-- | The last reported health status of the instance. \"Healthy\" means that
-- the instance is healthy and should remain in service. \"Unhealthy\"
-- means that the instance is unhealthy and that Amazon EC2 Auto Scaling
-- should terminate and replace it.
instance_healthStatus :: Lens.Lens' Instance Prelude.Text
instance_healthStatus :: Lens' Instance Text
instance_healthStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Text
healthStatus :: Text
$sel:healthStatus:Instance' :: Instance -> Text
healthStatus} -> Text
healthStatus) (\s :: Instance
s@Instance' {} Text
a -> Instance
s {$sel:healthStatus:Instance' :: Text
healthStatus = Text
a} :: Instance)

-- | Indicates whether the instance is protected from termination by Amazon
-- EC2 Auto Scaling when scaling in.
instance_protectedFromScaleIn :: Lens.Lens' Instance Prelude.Bool
instance_protectedFromScaleIn :: Lens' Instance Bool
instance_protectedFromScaleIn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Instance' {Bool
protectedFromScaleIn :: Bool
$sel:protectedFromScaleIn:Instance' :: Instance -> Bool
protectedFromScaleIn} -> Bool
protectedFromScaleIn) (\s :: Instance
s@Instance' {} Bool
a -> Instance
s {$sel:protectedFromScaleIn:Instance' :: Bool
protectedFromScaleIn = Bool
a} :: Instance)

instance Data.FromXML Instance where
  parseXML :: [Node] -> Either String Instance
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe LaunchTemplateSpecification
-> Maybe Text
-> Text
-> Text
-> LifecycleState
-> Text
-> Bool
-> Instance
Instance'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"InstanceType")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"LaunchConfigurationName")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"LaunchTemplate")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"WeightedCapacity")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"InstanceId")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"AvailabilityZone")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"LifecycleState")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"HealthStatus")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"ProtectedFromScaleIn")

instance Prelude.Hashable Instance where
  hashWithSalt :: Int -> Instance -> Int
hashWithSalt Int
_salt Instance' {Bool
Maybe Text
Maybe LaunchTemplateSpecification
Text
LifecycleState
protectedFromScaleIn :: Bool
healthStatus :: Text
lifecycleState :: LifecycleState
availabilityZone :: Text
instanceId :: Text
weightedCapacity :: Maybe Text
launchTemplate :: Maybe LaunchTemplateSpecification
launchConfigurationName :: Maybe Text
instanceType :: Maybe Text
$sel:protectedFromScaleIn:Instance' :: Instance -> Bool
$sel:healthStatus:Instance' :: Instance -> Text
$sel:lifecycleState:Instance' :: Instance -> LifecycleState
$sel:availabilityZone:Instance' :: Instance -> Text
$sel:instanceId:Instance' :: Instance -> Text
$sel:weightedCapacity:Instance' :: Instance -> Maybe Text
$sel:launchTemplate:Instance' :: Instance -> Maybe LaunchTemplateSpecification
$sel:launchConfigurationName:Instance' :: Instance -> Maybe Text
$sel:instanceType:Instance' :: Instance -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
instanceType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
launchConfigurationName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LaunchTemplateSpecification
launchTemplate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
weightedCapacity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
instanceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
availabilityZone
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LifecycleState
lifecycleState
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
healthStatus
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
protectedFromScaleIn

instance Prelude.NFData Instance where
  rnf :: Instance -> ()
rnf Instance' {Bool
Maybe Text
Maybe LaunchTemplateSpecification
Text
LifecycleState
protectedFromScaleIn :: Bool
healthStatus :: Text
lifecycleState :: LifecycleState
availabilityZone :: Text
instanceId :: Text
weightedCapacity :: Maybe Text
launchTemplate :: Maybe LaunchTemplateSpecification
launchConfigurationName :: Maybe Text
instanceType :: Maybe Text
$sel:protectedFromScaleIn:Instance' :: Instance -> Bool
$sel:healthStatus:Instance' :: Instance -> Text
$sel:lifecycleState:Instance' :: Instance -> LifecycleState
$sel:availabilityZone:Instance' :: Instance -> Text
$sel:instanceId:Instance' :: Instance -> Text
$sel:weightedCapacity:Instance' :: Instance -> Maybe Text
$sel:launchTemplate:Instance' :: Instance -> Maybe LaunchTemplateSpecification
$sel:launchConfigurationName:Instance' :: Instance -> Maybe Text
$sel:instanceType:Instance' :: Instance -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
instanceType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
launchConfigurationName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe LaunchTemplateSpecification
launchTemplate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
weightedCapacity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
instanceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
availabilityZone
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf LifecycleState
lifecycleState
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
healthStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
protectedFromScaleIn