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

import Amazonka.AutoScaling.Types.InstancesDistribution
import Amazonka.AutoScaling.Types.LaunchTemplate
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a mixed instances policy. A mixed instances policy contains
-- the instance types Amazon EC2 Auto Scaling can launch, and other
-- information Amazon EC2 Auto Scaling can use to launch instances to help
-- you optimize your costs. For more information, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html Auto Scaling groups with multiple instance types and purchase options>
-- in the /Amazon EC2 Auto Scaling User Guide/.
--
-- /See:/ 'newMixedInstancesPolicy' smart constructor.
data MixedInstancesPolicy = MixedInstancesPolicy'
  { -- | Specifies the launch template to use and the instance types (overrides)
    -- that are used to provision EC2 instances to fulfill On-Demand and Spot
    -- capacities. Required when creating a mixed instances policy.
    MixedInstancesPolicy -> Maybe LaunchTemplate
launchTemplate :: Prelude.Maybe LaunchTemplate,
    -- | Specifies the instances distribution. If not provided, the value for
    -- each property in @InstancesDistribution@ uses a default value.
    MixedInstancesPolicy -> Maybe InstancesDistribution
instancesDistribution :: Prelude.Maybe InstancesDistribution
  }
  deriving (MixedInstancesPolicy -> MixedInstancesPolicy -> Bool
(MixedInstancesPolicy -> MixedInstancesPolicy -> Bool)
-> (MixedInstancesPolicy -> MixedInstancesPolicy -> Bool)
-> Eq MixedInstancesPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MixedInstancesPolicy -> MixedInstancesPolicy -> Bool
$c/= :: MixedInstancesPolicy -> MixedInstancesPolicy -> Bool
== :: MixedInstancesPolicy -> MixedInstancesPolicy -> Bool
$c== :: MixedInstancesPolicy -> MixedInstancesPolicy -> Bool
Prelude.Eq, ReadPrec [MixedInstancesPolicy]
ReadPrec MixedInstancesPolicy
Int -> ReadS MixedInstancesPolicy
ReadS [MixedInstancesPolicy]
(Int -> ReadS MixedInstancesPolicy)
-> ReadS [MixedInstancesPolicy]
-> ReadPrec MixedInstancesPolicy
-> ReadPrec [MixedInstancesPolicy]
-> Read MixedInstancesPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MixedInstancesPolicy]
$creadListPrec :: ReadPrec [MixedInstancesPolicy]
readPrec :: ReadPrec MixedInstancesPolicy
$creadPrec :: ReadPrec MixedInstancesPolicy
readList :: ReadS [MixedInstancesPolicy]
$creadList :: ReadS [MixedInstancesPolicy]
readsPrec :: Int -> ReadS MixedInstancesPolicy
$creadsPrec :: Int -> ReadS MixedInstancesPolicy
Prelude.Read, Int -> MixedInstancesPolicy -> ShowS
[MixedInstancesPolicy] -> ShowS
MixedInstancesPolicy -> String
(Int -> MixedInstancesPolicy -> ShowS)
-> (MixedInstancesPolicy -> String)
-> ([MixedInstancesPolicy] -> ShowS)
-> Show MixedInstancesPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MixedInstancesPolicy] -> ShowS
$cshowList :: [MixedInstancesPolicy] -> ShowS
show :: MixedInstancesPolicy -> String
$cshow :: MixedInstancesPolicy -> String
showsPrec :: Int -> MixedInstancesPolicy -> ShowS
$cshowsPrec :: Int -> MixedInstancesPolicy -> ShowS
Prelude.Show, (forall x. MixedInstancesPolicy -> Rep MixedInstancesPolicy x)
-> (forall x. Rep MixedInstancesPolicy x -> MixedInstancesPolicy)
-> Generic MixedInstancesPolicy
forall x. Rep MixedInstancesPolicy x -> MixedInstancesPolicy
forall x. MixedInstancesPolicy -> Rep MixedInstancesPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MixedInstancesPolicy x -> MixedInstancesPolicy
$cfrom :: forall x. MixedInstancesPolicy -> Rep MixedInstancesPolicy x
Prelude.Generic)

-- |
-- Create a value of 'MixedInstancesPolicy' 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:
--
-- 'launchTemplate', 'mixedInstancesPolicy_launchTemplate' - Specifies the launch template to use and the instance types (overrides)
-- that are used to provision EC2 instances to fulfill On-Demand and Spot
-- capacities. Required when creating a mixed instances policy.
--
-- 'instancesDistribution', 'mixedInstancesPolicy_instancesDistribution' - Specifies the instances distribution. If not provided, the value for
-- each property in @InstancesDistribution@ uses a default value.
newMixedInstancesPolicy ::
  MixedInstancesPolicy
newMixedInstancesPolicy :: MixedInstancesPolicy
newMixedInstancesPolicy =
  MixedInstancesPolicy' :: Maybe LaunchTemplate
-> Maybe InstancesDistribution -> MixedInstancesPolicy
MixedInstancesPolicy'
    { $sel:launchTemplate:MixedInstancesPolicy' :: Maybe LaunchTemplate
launchTemplate =
        Maybe LaunchTemplate
forall a. Maybe a
Prelude.Nothing,
      $sel:instancesDistribution:MixedInstancesPolicy' :: Maybe InstancesDistribution
instancesDistribution = Maybe InstancesDistribution
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the launch template to use and the instance types (overrides)
-- that are used to provision EC2 instances to fulfill On-Demand and Spot
-- capacities. Required when creating a mixed instances policy.
mixedInstancesPolicy_launchTemplate :: Lens.Lens' MixedInstancesPolicy (Prelude.Maybe LaunchTemplate)
mixedInstancesPolicy_launchTemplate :: (Maybe LaunchTemplate -> f (Maybe LaunchTemplate))
-> MixedInstancesPolicy -> f MixedInstancesPolicy
mixedInstancesPolicy_launchTemplate = (MixedInstancesPolicy -> Maybe LaunchTemplate)
-> (MixedInstancesPolicy
    -> Maybe LaunchTemplate -> MixedInstancesPolicy)
-> Lens
     MixedInstancesPolicy
     MixedInstancesPolicy
     (Maybe LaunchTemplate)
     (Maybe LaunchTemplate)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MixedInstancesPolicy' {Maybe LaunchTemplate
launchTemplate :: Maybe LaunchTemplate
$sel:launchTemplate:MixedInstancesPolicy' :: MixedInstancesPolicy -> Maybe LaunchTemplate
launchTemplate} -> Maybe LaunchTemplate
launchTemplate) (\s :: MixedInstancesPolicy
s@MixedInstancesPolicy' {} Maybe LaunchTemplate
a -> MixedInstancesPolicy
s {$sel:launchTemplate:MixedInstancesPolicy' :: Maybe LaunchTemplate
launchTemplate = Maybe LaunchTemplate
a} :: MixedInstancesPolicy)

-- | Specifies the instances distribution. If not provided, the value for
-- each property in @InstancesDistribution@ uses a default value.
mixedInstancesPolicy_instancesDistribution :: Lens.Lens' MixedInstancesPolicy (Prelude.Maybe InstancesDistribution)
mixedInstancesPolicy_instancesDistribution :: (Maybe InstancesDistribution -> f (Maybe InstancesDistribution))
-> MixedInstancesPolicy -> f MixedInstancesPolicy
mixedInstancesPolicy_instancesDistribution = (MixedInstancesPolicy -> Maybe InstancesDistribution)
-> (MixedInstancesPolicy
    -> Maybe InstancesDistribution -> MixedInstancesPolicy)
-> Lens
     MixedInstancesPolicy
     MixedInstancesPolicy
     (Maybe InstancesDistribution)
     (Maybe InstancesDistribution)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MixedInstancesPolicy' {Maybe InstancesDistribution
instancesDistribution :: Maybe InstancesDistribution
$sel:instancesDistribution:MixedInstancesPolicy' :: MixedInstancesPolicy -> Maybe InstancesDistribution
instancesDistribution} -> Maybe InstancesDistribution
instancesDistribution) (\s :: MixedInstancesPolicy
s@MixedInstancesPolicy' {} Maybe InstancesDistribution
a -> MixedInstancesPolicy
s {$sel:instancesDistribution:MixedInstancesPolicy' :: Maybe InstancesDistribution
instancesDistribution = Maybe InstancesDistribution
a} :: MixedInstancesPolicy)

instance Core.FromXML MixedInstancesPolicy where
  parseXML :: [Node] -> Either String MixedInstancesPolicy
parseXML [Node]
x =
    Maybe LaunchTemplate
-> Maybe InstancesDistribution -> MixedInstancesPolicy
MixedInstancesPolicy'
      (Maybe LaunchTemplate
 -> Maybe InstancesDistribution -> MixedInstancesPolicy)
-> Either String (Maybe LaunchTemplate)
-> Either
     String (Maybe InstancesDistribution -> MixedInstancesPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe LaunchTemplate)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"LaunchTemplate")
      Either String (Maybe InstancesDistribution -> MixedInstancesPolicy)
-> Either String (Maybe InstancesDistribution)
-> Either String MixedInstancesPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe InstancesDistribution)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"InstancesDistribution")

instance Prelude.Hashable MixedInstancesPolicy

instance Prelude.NFData MixedInstancesPolicy

instance Core.ToQuery MixedInstancesPolicy where
  toQuery :: MixedInstancesPolicy -> QueryString
toQuery MixedInstancesPolicy' {Maybe InstancesDistribution
Maybe LaunchTemplate
instancesDistribution :: Maybe InstancesDistribution
launchTemplate :: Maybe LaunchTemplate
$sel:instancesDistribution:MixedInstancesPolicy' :: MixedInstancesPolicy -> Maybe InstancesDistribution
$sel:launchTemplate:MixedInstancesPolicy' :: MixedInstancesPolicy -> Maybe LaunchTemplate
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"LaunchTemplate" ByteString -> Maybe LaunchTemplate -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe LaunchTemplate
launchTemplate,
        ByteString
"InstancesDistribution"
          ByteString -> Maybe InstancesDistribution -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe InstancesDistribution
instancesDistribution
      ]