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

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

-- | Describes an EC2 instance.
--
-- /See:/ 'newInstance' smart constructor.
data Instance = 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 -> Maybe Text
weightedCapacity :: Prelude.Maybe Prelude.Text,
    -- | 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 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
(Instance -> Instance -> Bool)
-> (Instance -> Instance -> Bool) -> Eq Instance
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]
(Int -> ReadS Instance)
-> ReadS [Instance]
-> ReadPrec Instance
-> ReadPrec [Instance]
-> Read 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
(Int -> Instance -> ShowS)
-> (Instance -> String) -> ([Instance] -> ShowS) -> Show Instance
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. Instance -> Rep Instance x)
-> (forall x. Rep Instance x -> Instance) -> Generic Instance
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:
--
-- '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.
--
-- '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.
--
-- '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' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe LaunchTemplateSpecification
-> Text
-> Text
-> LifecycleState
-> Text
-> Bool
-> Instance
Instance'
      { $sel:weightedCapacity:Instance' :: Maybe Text
weightedCapacity = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:instanceType:Instance' :: Maybe Text
instanceType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:launchConfigurationName:Instance' :: Maybe Text
launchConfigurationName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:launchTemplate:Instance' :: Maybe LaunchTemplateSpecification
launchTemplate = Maybe LaunchTemplateSpecification
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 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 :: (Maybe Text -> f (Maybe Text)) -> Instance -> f Instance
instance_weightedCapacity = (Instance -> Maybe Text)
-> (Instance -> Maybe Text -> Instance)
-> Lens Instance Instance (Maybe Text) (Maybe Text)
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 instance type of the EC2 instance.
instance_instanceType :: Lens.Lens' Instance (Prelude.Maybe Prelude.Text)
instance_instanceType :: (Maybe Text -> f (Maybe Text)) -> Instance -> f Instance
instance_instanceType = (Instance -> Maybe Text)
-> (Instance -> Maybe Text -> Instance)
-> Lens Instance Instance (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> Instance -> f Instance
instance_launchConfigurationName = (Instance -> Maybe Text)
-> (Instance -> Maybe Text -> Instance)
-> Lens Instance Instance (Maybe Text) (Maybe Text)
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 :: (Maybe LaunchTemplateSpecification
 -> f (Maybe LaunchTemplateSpecification))
-> Instance -> f Instance
instance_launchTemplate = (Instance -> Maybe LaunchTemplateSpecification)
-> (Instance -> Maybe LaunchTemplateSpecification -> Instance)
-> Lens
     Instance
     Instance
     (Maybe LaunchTemplateSpecification)
     (Maybe LaunchTemplateSpecification)
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 ID of the instance.
instance_instanceId :: Lens.Lens' Instance Prelude.Text
instance_instanceId :: (Text -> f Text) -> Instance -> f Instance
instance_instanceId = (Instance -> Text)
-> (Instance -> Text -> Instance)
-> Lens Instance Instance Text Text
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 :: (Text -> f Text) -> Instance -> f Instance
instance_availabilityZone = (Instance -> Text)
-> (Instance -> Text -> Instance)
-> Lens Instance Instance Text Text
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 :: (LifecycleState -> f LifecycleState) -> Instance -> f Instance
instance_lifecycleState = (Instance -> LifecycleState)
-> (Instance -> LifecycleState -> Instance)
-> Lens Instance Instance LifecycleState 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 :: (Text -> f Text) -> Instance -> f Instance
instance_healthStatus = (Instance -> Text)
-> (Instance -> Text -> Instance)
-> Lens Instance Instance Text Text
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 :: (Bool -> f Bool) -> Instance -> f Instance
instance_protectedFromScaleIn = (Instance -> Bool)
-> (Instance -> Bool -> Instance)
-> Lens Instance Instance Bool Bool
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 Core.FromXML Instance where
  parseXML :: [Node] -> Either String Instance
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe LaunchTemplateSpecification
-> Text
-> Text
-> LifecycleState
-> Text
-> Bool
-> Instance
Instance'
      (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe LaunchTemplateSpecification
 -> Text
 -> Text
 -> LifecycleState
 -> Text
 -> Bool
 -> Instance)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe Text
      -> Maybe LaunchTemplateSpecification
      -> Text
      -> Text
      -> LifecycleState
      -> Text
      -> Bool
      -> Instance)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"WeightedCapacity")
      Either
  String
  (Maybe Text
   -> Maybe Text
   -> Maybe LaunchTemplateSpecification
   -> Text
   -> Text
   -> LifecycleState
   -> Text
   -> Bool
   -> Instance)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe LaunchTemplateSpecification
      -> Text
      -> Text
      -> LifecycleState
      -> Text
      -> Bool
      -> Instance)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"InstanceType")
      Either
  String
  (Maybe Text
   -> Maybe LaunchTemplateSpecification
   -> Text
   -> Text
   -> LifecycleState
   -> Text
   -> Bool
   -> Instance)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe LaunchTemplateSpecification
      -> Text -> Text -> LifecycleState -> Text -> Bool -> Instance)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"LaunchConfigurationName")
      Either
  String
  (Maybe LaunchTemplateSpecification
   -> Text -> Text -> LifecycleState -> Text -> Bool -> Instance)
-> Either String (Maybe LaunchTemplateSpecification)
-> Either
     String (Text -> Text -> LifecycleState -> Text -> Bool -> Instance)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe LaunchTemplateSpecification)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"LaunchTemplate")
      Either
  String (Text -> Text -> LifecycleState -> Text -> Bool -> Instance)
-> Either String Text
-> Either
     String (Text -> LifecycleState -> Text -> Bool -> Instance)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"InstanceId")
      Either String (Text -> LifecycleState -> Text -> Bool -> Instance)
-> Either String Text
-> Either String (LifecycleState -> Text -> Bool -> Instance)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"AvailabilityZone")
      Either String (LifecycleState -> Text -> Bool -> Instance)
-> Either String LifecycleState
-> Either String (Text -> Bool -> Instance)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String LifecycleState
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"LifecycleState")
      Either String (Text -> Bool -> Instance)
-> Either String Text -> Either String (Bool -> Instance)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"HealthStatus")
      Either String (Bool -> Instance)
-> Either String Bool -> Either String Instance
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Bool
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ProtectedFromScaleIn")

instance Prelude.Hashable Instance

instance Prelude.NFData Instance