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

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

-- | Describes an override for a launch template. The maximum number of
-- instance types that can be associated with an Auto Scaling group is 40.
-- The maximum number of distinct launch templates you can define for an
-- Auto Scaling group is 20. For more information about configuring
-- overrides, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-override-options.html Configuring overrides>
-- in the /Amazon EC2 Auto Scaling User Guide/.
--
-- /See:/ 'newLaunchTemplateOverrides' smart constructor.
data LaunchTemplateOverrides = LaunchTemplateOverrides'
  { -- | The number of capacity units provided by the specified instance type in
    -- terms of virtual CPUs, memory, storage, throughput, or other relative
    -- performance characteristic. When a Spot or On-Demand Instance is
    -- provisioned, the capacity units count toward the desired capacity.
    -- Amazon EC2 Auto Scaling provisions instances until the desired capacity
    -- is totally fulfilled, even if this results in an overage. For example,
    -- if there are 2 units remaining to fulfill capacity, and Amazon EC2 Auto
    -- Scaling can only provision an instance with a @WeightedCapacity@ of 5
    -- units, the instance is provisioned, and the desired capacity is exceeded
    -- by 3 units. For more information, see
    -- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html Instance weighting for Amazon EC2 Auto Scaling>
    -- in the /Amazon EC2 Auto Scaling User Guide/. Value must be in the range
    -- of 1 to 999.
    LaunchTemplateOverrides -> Maybe Text
weightedCapacity :: Prelude.Maybe Prelude.Text,
    -- | The instance type, such as @m3.xlarge@. You must use an instance type
    -- that is supported in your requested Region and Availability Zones. For
    -- more information, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html Instance types>
    -- in the /Amazon Elastic Compute Cloud User Guide/.
    LaunchTemplateOverrides -> Maybe Text
instanceType :: Prelude.Maybe Prelude.Text,
    -- | Provides the launch template to be used when launching the instance
    -- type. For example, some instance types might require a launch template
    -- with a different AMI. If not provided, Amazon EC2 Auto Scaling uses the
    -- launch template that\'s defined for your mixed instances policy. For
    -- more information, see
    -- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-launch-template-overrides.html Specifying a different launch template for an instance type>
    -- in the /Amazon EC2 Auto Scaling User Guide/.
    LaunchTemplateOverrides -> Maybe LaunchTemplateSpecification
launchTemplateSpecification :: Prelude.Maybe LaunchTemplateSpecification
  }
  deriving (LaunchTemplateOverrides -> LaunchTemplateOverrides -> Bool
(LaunchTemplateOverrides -> LaunchTemplateOverrides -> Bool)
-> (LaunchTemplateOverrides -> LaunchTemplateOverrides -> Bool)
-> Eq LaunchTemplateOverrides
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LaunchTemplateOverrides -> LaunchTemplateOverrides -> Bool
$c/= :: LaunchTemplateOverrides -> LaunchTemplateOverrides -> Bool
== :: LaunchTemplateOverrides -> LaunchTemplateOverrides -> Bool
$c== :: LaunchTemplateOverrides -> LaunchTemplateOverrides -> Bool
Prelude.Eq, ReadPrec [LaunchTemplateOverrides]
ReadPrec LaunchTemplateOverrides
Int -> ReadS LaunchTemplateOverrides
ReadS [LaunchTemplateOverrides]
(Int -> ReadS LaunchTemplateOverrides)
-> ReadS [LaunchTemplateOverrides]
-> ReadPrec LaunchTemplateOverrides
-> ReadPrec [LaunchTemplateOverrides]
-> Read LaunchTemplateOverrides
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LaunchTemplateOverrides]
$creadListPrec :: ReadPrec [LaunchTemplateOverrides]
readPrec :: ReadPrec LaunchTemplateOverrides
$creadPrec :: ReadPrec LaunchTemplateOverrides
readList :: ReadS [LaunchTemplateOverrides]
$creadList :: ReadS [LaunchTemplateOverrides]
readsPrec :: Int -> ReadS LaunchTemplateOverrides
$creadsPrec :: Int -> ReadS LaunchTemplateOverrides
Prelude.Read, Int -> LaunchTemplateOverrides -> ShowS
[LaunchTemplateOverrides] -> ShowS
LaunchTemplateOverrides -> String
(Int -> LaunchTemplateOverrides -> ShowS)
-> (LaunchTemplateOverrides -> String)
-> ([LaunchTemplateOverrides] -> ShowS)
-> Show LaunchTemplateOverrides
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LaunchTemplateOverrides] -> ShowS
$cshowList :: [LaunchTemplateOverrides] -> ShowS
show :: LaunchTemplateOverrides -> String
$cshow :: LaunchTemplateOverrides -> String
showsPrec :: Int -> LaunchTemplateOverrides -> ShowS
$cshowsPrec :: Int -> LaunchTemplateOverrides -> ShowS
Prelude.Show, (forall x.
 LaunchTemplateOverrides -> Rep LaunchTemplateOverrides x)
-> (forall x.
    Rep LaunchTemplateOverrides x -> LaunchTemplateOverrides)
-> Generic LaunchTemplateOverrides
forall x. Rep LaunchTemplateOverrides x -> LaunchTemplateOverrides
forall x. LaunchTemplateOverrides -> Rep LaunchTemplateOverrides x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LaunchTemplateOverrides x -> LaunchTemplateOverrides
$cfrom :: forall x. LaunchTemplateOverrides -> Rep LaunchTemplateOverrides x
Prelude.Generic)

-- |
-- Create a value of 'LaunchTemplateOverrides' 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', 'launchTemplateOverrides_weightedCapacity' - The number of capacity units provided by the specified instance type in
-- terms of virtual CPUs, memory, storage, throughput, or other relative
-- performance characteristic. When a Spot or On-Demand Instance is
-- provisioned, the capacity units count toward the desired capacity.
-- Amazon EC2 Auto Scaling provisions instances until the desired capacity
-- is totally fulfilled, even if this results in an overage. For example,
-- if there are 2 units remaining to fulfill capacity, and Amazon EC2 Auto
-- Scaling can only provision an instance with a @WeightedCapacity@ of 5
-- units, the instance is provisioned, and the desired capacity is exceeded
-- by 3 units. For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html Instance weighting for Amazon EC2 Auto Scaling>
-- in the /Amazon EC2 Auto Scaling User Guide/. Value must be in the range
-- of 1 to 999.
--
-- 'instanceType', 'launchTemplateOverrides_instanceType' - The instance type, such as @m3.xlarge@. You must use an instance type
-- that is supported in your requested Region and Availability Zones. For
-- more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html Instance types>
-- in the /Amazon Elastic Compute Cloud User Guide/.
--
-- 'launchTemplateSpecification', 'launchTemplateOverrides_launchTemplateSpecification' - Provides the launch template to be used when launching the instance
-- type. For example, some instance types might require a launch template
-- with a different AMI. If not provided, Amazon EC2 Auto Scaling uses the
-- launch template that\'s defined for your mixed instances policy. For
-- more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-launch-template-overrides.html Specifying a different launch template for an instance type>
-- in the /Amazon EC2 Auto Scaling User Guide/.
newLaunchTemplateOverrides ::
  LaunchTemplateOverrides
newLaunchTemplateOverrides :: LaunchTemplateOverrides
newLaunchTemplateOverrides =
  LaunchTemplateOverrides' :: Maybe Text
-> Maybe Text
-> Maybe LaunchTemplateSpecification
-> LaunchTemplateOverrides
LaunchTemplateOverrides'
    { $sel:weightedCapacity:LaunchTemplateOverrides' :: Maybe Text
weightedCapacity =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceType:LaunchTemplateOverrides' :: Maybe Text
instanceType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:launchTemplateSpecification:LaunchTemplateOverrides' :: Maybe LaunchTemplateSpecification
launchTemplateSpecification = Maybe LaunchTemplateSpecification
forall a. Maybe a
Prelude.Nothing
    }

-- | The number of capacity units provided by the specified instance type in
-- terms of virtual CPUs, memory, storage, throughput, or other relative
-- performance characteristic. When a Spot or On-Demand Instance is
-- provisioned, the capacity units count toward the desired capacity.
-- Amazon EC2 Auto Scaling provisions instances until the desired capacity
-- is totally fulfilled, even if this results in an overage. For example,
-- if there are 2 units remaining to fulfill capacity, and Amazon EC2 Auto
-- Scaling can only provision an instance with a @WeightedCapacity@ of 5
-- units, the instance is provisioned, and the desired capacity is exceeded
-- by 3 units. For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html Instance weighting for Amazon EC2 Auto Scaling>
-- in the /Amazon EC2 Auto Scaling User Guide/. Value must be in the range
-- of 1 to 999.
launchTemplateOverrides_weightedCapacity :: Lens.Lens' LaunchTemplateOverrides (Prelude.Maybe Prelude.Text)
launchTemplateOverrides_weightedCapacity :: (Maybe Text -> f (Maybe Text))
-> LaunchTemplateOverrides -> f LaunchTemplateOverrides
launchTemplateOverrides_weightedCapacity = (LaunchTemplateOverrides -> Maybe Text)
-> (LaunchTemplateOverrides
    -> Maybe Text -> LaunchTemplateOverrides)
-> Lens
     LaunchTemplateOverrides
     LaunchTemplateOverrides
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LaunchTemplateOverrides' {Maybe Text
weightedCapacity :: Maybe Text
$sel:weightedCapacity:LaunchTemplateOverrides' :: LaunchTemplateOverrides -> Maybe Text
weightedCapacity} -> Maybe Text
weightedCapacity) (\s :: LaunchTemplateOverrides
s@LaunchTemplateOverrides' {} Maybe Text
a -> LaunchTemplateOverrides
s {$sel:weightedCapacity:LaunchTemplateOverrides' :: Maybe Text
weightedCapacity = Maybe Text
a} :: LaunchTemplateOverrides)

-- | The instance type, such as @m3.xlarge@. You must use an instance type
-- that is supported in your requested Region and Availability Zones. For
-- more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html Instance types>
-- in the /Amazon Elastic Compute Cloud User Guide/.
launchTemplateOverrides_instanceType :: Lens.Lens' LaunchTemplateOverrides (Prelude.Maybe Prelude.Text)
launchTemplateOverrides_instanceType :: (Maybe Text -> f (Maybe Text))
-> LaunchTemplateOverrides -> f LaunchTemplateOverrides
launchTemplateOverrides_instanceType = (LaunchTemplateOverrides -> Maybe Text)
-> (LaunchTemplateOverrides
    -> Maybe Text -> LaunchTemplateOverrides)
-> Lens
     LaunchTemplateOverrides
     LaunchTemplateOverrides
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LaunchTemplateOverrides' {Maybe Text
instanceType :: Maybe Text
$sel:instanceType:LaunchTemplateOverrides' :: LaunchTemplateOverrides -> Maybe Text
instanceType} -> Maybe Text
instanceType) (\s :: LaunchTemplateOverrides
s@LaunchTemplateOverrides' {} Maybe Text
a -> LaunchTemplateOverrides
s {$sel:instanceType:LaunchTemplateOverrides' :: Maybe Text
instanceType = Maybe Text
a} :: LaunchTemplateOverrides)

-- | Provides the launch template to be used when launching the instance
-- type. For example, some instance types might require a launch template
-- with a different AMI. If not provided, Amazon EC2 Auto Scaling uses the
-- launch template that\'s defined for your mixed instances policy. For
-- more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-launch-template-overrides.html Specifying a different launch template for an instance type>
-- in the /Amazon EC2 Auto Scaling User Guide/.
launchTemplateOverrides_launchTemplateSpecification :: Lens.Lens' LaunchTemplateOverrides (Prelude.Maybe LaunchTemplateSpecification)
launchTemplateOverrides_launchTemplateSpecification :: (Maybe LaunchTemplateSpecification
 -> f (Maybe LaunchTemplateSpecification))
-> LaunchTemplateOverrides -> f LaunchTemplateOverrides
launchTemplateOverrides_launchTemplateSpecification = (LaunchTemplateOverrides -> Maybe LaunchTemplateSpecification)
-> (LaunchTemplateOverrides
    -> Maybe LaunchTemplateSpecification -> LaunchTemplateOverrides)
-> Lens
     LaunchTemplateOverrides
     LaunchTemplateOverrides
     (Maybe LaunchTemplateSpecification)
     (Maybe LaunchTemplateSpecification)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LaunchTemplateOverrides' {Maybe LaunchTemplateSpecification
launchTemplateSpecification :: Maybe LaunchTemplateSpecification
$sel:launchTemplateSpecification:LaunchTemplateOverrides' :: LaunchTemplateOverrides -> Maybe LaunchTemplateSpecification
launchTemplateSpecification} -> Maybe LaunchTemplateSpecification
launchTemplateSpecification) (\s :: LaunchTemplateOverrides
s@LaunchTemplateOverrides' {} Maybe LaunchTemplateSpecification
a -> LaunchTemplateOverrides
s {$sel:launchTemplateSpecification:LaunchTemplateOverrides' :: Maybe LaunchTemplateSpecification
launchTemplateSpecification = Maybe LaunchTemplateSpecification
a} :: LaunchTemplateOverrides)

instance Core.FromXML LaunchTemplateOverrides where
  parseXML :: [Node] -> Either String LaunchTemplateOverrides
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe LaunchTemplateSpecification
-> LaunchTemplateOverrides
LaunchTemplateOverrides'
      (Maybe Text
 -> Maybe Text
 -> Maybe LaunchTemplateSpecification
 -> LaunchTemplateOverrides)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe LaunchTemplateSpecification -> LaunchTemplateOverrides)
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 LaunchTemplateSpecification -> LaunchTemplateOverrides)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe LaunchTemplateSpecification -> LaunchTemplateOverrides)
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 LaunchTemplateSpecification -> LaunchTemplateOverrides)
-> Either String (Maybe LaunchTemplateSpecification)
-> Either String LaunchTemplateOverrides
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
"LaunchTemplateSpecification")

instance Prelude.Hashable LaunchTemplateOverrides

instance Prelude.NFData LaunchTemplateOverrides

instance Core.ToQuery LaunchTemplateOverrides where
  toQuery :: LaunchTemplateOverrides -> QueryString
toQuery LaunchTemplateOverrides' {Maybe Text
Maybe LaunchTemplateSpecification
launchTemplateSpecification :: Maybe LaunchTemplateSpecification
instanceType :: Maybe Text
weightedCapacity :: Maybe Text
$sel:launchTemplateSpecification:LaunchTemplateOverrides' :: LaunchTemplateOverrides -> Maybe LaunchTemplateSpecification
$sel:instanceType:LaunchTemplateOverrides' :: LaunchTemplateOverrides -> Maybe Text
$sel:weightedCapacity:LaunchTemplateOverrides' :: LaunchTemplateOverrides -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"WeightedCapacity" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
weightedCapacity,
        ByteString
"InstanceType" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
instanceType,
        ByteString
"LaunchTemplateSpecification"
          ByteString -> Maybe LaunchTemplateSpecification -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe LaunchTemplateSpecification
launchTemplateSpecification
      ]