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

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

-- | Describes a launch template and overrides.
--
-- You specify these properties as part of a mixed instances policy.
--
-- When you update the launch template or overrides in the
-- UpdateAutoScalingGroup API call, existing Amazon EC2 instances continue
-- to run. When scale out occurs, Amazon EC2 Auto Scaling launches
-- instances to match the new settings. When scale in occurs, Amazon EC2
-- Auto Scaling terminates instances according to the group\'s termination
-- policies.
--
-- /See:/ 'newLaunchTemplate' smart constructor.
data LaunchTemplate = LaunchTemplate'
  { -- | Any properties that you specify override the same properties in the
    -- launch template. If not provided, Amazon EC2 Auto Scaling uses the
    -- instance type specified in the launch template when it launches an
    -- instance.
    LaunchTemplate -> Maybe [LaunchTemplateOverrides]
overrides :: Prelude.Maybe [LaunchTemplateOverrides],
    -- | The launch template to use.
    LaunchTemplate -> Maybe LaunchTemplateSpecification
launchTemplateSpecification :: Prelude.Maybe LaunchTemplateSpecification
  }
  deriving (LaunchTemplate -> LaunchTemplate -> Bool
(LaunchTemplate -> LaunchTemplate -> Bool)
-> (LaunchTemplate -> LaunchTemplate -> Bool) -> Eq LaunchTemplate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LaunchTemplate -> LaunchTemplate -> Bool
$c/= :: LaunchTemplate -> LaunchTemplate -> Bool
== :: LaunchTemplate -> LaunchTemplate -> Bool
$c== :: LaunchTemplate -> LaunchTemplate -> Bool
Prelude.Eq, ReadPrec [LaunchTemplate]
ReadPrec LaunchTemplate
Int -> ReadS LaunchTemplate
ReadS [LaunchTemplate]
(Int -> ReadS LaunchTemplate)
-> ReadS [LaunchTemplate]
-> ReadPrec LaunchTemplate
-> ReadPrec [LaunchTemplate]
-> Read LaunchTemplate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LaunchTemplate]
$creadListPrec :: ReadPrec [LaunchTemplate]
readPrec :: ReadPrec LaunchTemplate
$creadPrec :: ReadPrec LaunchTemplate
readList :: ReadS [LaunchTemplate]
$creadList :: ReadS [LaunchTemplate]
readsPrec :: Int -> ReadS LaunchTemplate
$creadsPrec :: Int -> ReadS LaunchTemplate
Prelude.Read, Int -> LaunchTemplate -> ShowS
[LaunchTemplate] -> ShowS
LaunchTemplate -> String
(Int -> LaunchTemplate -> ShowS)
-> (LaunchTemplate -> String)
-> ([LaunchTemplate] -> ShowS)
-> Show LaunchTemplate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LaunchTemplate] -> ShowS
$cshowList :: [LaunchTemplate] -> ShowS
show :: LaunchTemplate -> String
$cshow :: LaunchTemplate -> String
showsPrec :: Int -> LaunchTemplate -> ShowS
$cshowsPrec :: Int -> LaunchTemplate -> ShowS
Prelude.Show, (forall x. LaunchTemplate -> Rep LaunchTemplate x)
-> (forall x. Rep LaunchTemplate x -> LaunchTemplate)
-> Generic LaunchTemplate
forall x. Rep LaunchTemplate x -> LaunchTemplate
forall x. LaunchTemplate -> Rep LaunchTemplate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LaunchTemplate x -> LaunchTemplate
$cfrom :: forall x. LaunchTemplate -> Rep LaunchTemplate x
Prelude.Generic)

-- |
-- Create a value of 'LaunchTemplate' 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:
--
-- 'overrides', 'launchTemplate_overrides' - Any properties that you specify override the same properties in the
-- launch template. If not provided, Amazon EC2 Auto Scaling uses the
-- instance type specified in the launch template when it launches an
-- instance.
--
-- 'launchTemplateSpecification', 'launchTemplate_launchTemplateSpecification' - The launch template to use.
newLaunchTemplate ::
  LaunchTemplate
newLaunchTemplate :: LaunchTemplate
newLaunchTemplate =
  LaunchTemplate' :: Maybe [LaunchTemplateOverrides]
-> Maybe LaunchTemplateSpecification -> LaunchTemplate
LaunchTemplate'
    { $sel:overrides:LaunchTemplate' :: Maybe [LaunchTemplateOverrides]
overrides = Maybe [LaunchTemplateOverrides]
forall a. Maybe a
Prelude.Nothing,
      $sel:launchTemplateSpecification:LaunchTemplate' :: Maybe LaunchTemplateSpecification
launchTemplateSpecification = Maybe LaunchTemplateSpecification
forall a. Maybe a
Prelude.Nothing
    }

-- | Any properties that you specify override the same properties in the
-- launch template. If not provided, Amazon EC2 Auto Scaling uses the
-- instance type specified in the launch template when it launches an
-- instance.
launchTemplate_overrides :: Lens.Lens' LaunchTemplate (Prelude.Maybe [LaunchTemplateOverrides])
launchTemplate_overrides :: (Maybe [LaunchTemplateOverrides]
 -> f (Maybe [LaunchTemplateOverrides]))
-> LaunchTemplate -> f LaunchTemplate
launchTemplate_overrides = (LaunchTemplate -> Maybe [LaunchTemplateOverrides])
-> (LaunchTemplate
    -> Maybe [LaunchTemplateOverrides] -> LaunchTemplate)
-> Lens
     LaunchTemplate
     LaunchTemplate
     (Maybe [LaunchTemplateOverrides])
     (Maybe [LaunchTemplateOverrides])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LaunchTemplate' {Maybe [LaunchTemplateOverrides]
overrides :: Maybe [LaunchTemplateOverrides]
$sel:overrides:LaunchTemplate' :: LaunchTemplate -> Maybe [LaunchTemplateOverrides]
overrides} -> Maybe [LaunchTemplateOverrides]
overrides) (\s :: LaunchTemplate
s@LaunchTemplate' {} Maybe [LaunchTemplateOverrides]
a -> LaunchTemplate
s {$sel:overrides:LaunchTemplate' :: Maybe [LaunchTemplateOverrides]
overrides = Maybe [LaunchTemplateOverrides]
a} :: LaunchTemplate) ((Maybe [LaunchTemplateOverrides]
  -> f (Maybe [LaunchTemplateOverrides]))
 -> LaunchTemplate -> f LaunchTemplate)
-> ((Maybe [LaunchTemplateOverrides]
     -> f (Maybe [LaunchTemplateOverrides]))
    -> Maybe [LaunchTemplateOverrides]
    -> f (Maybe [LaunchTemplateOverrides]))
-> (Maybe [LaunchTemplateOverrides]
    -> f (Maybe [LaunchTemplateOverrides]))
-> LaunchTemplate
-> f LaunchTemplate
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [LaunchTemplateOverrides]
  [LaunchTemplateOverrides]
  [LaunchTemplateOverrides]
  [LaunchTemplateOverrides]
-> Iso
     (Maybe [LaunchTemplateOverrides])
     (Maybe [LaunchTemplateOverrides])
     (Maybe [LaunchTemplateOverrides])
     (Maybe [LaunchTemplateOverrides])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [LaunchTemplateOverrides]
  [LaunchTemplateOverrides]
  [LaunchTemplateOverrides]
  [LaunchTemplateOverrides]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The launch template to use.
launchTemplate_launchTemplateSpecification :: Lens.Lens' LaunchTemplate (Prelude.Maybe LaunchTemplateSpecification)
launchTemplate_launchTemplateSpecification :: (Maybe LaunchTemplateSpecification
 -> f (Maybe LaunchTemplateSpecification))
-> LaunchTemplate -> f LaunchTemplate
launchTemplate_launchTemplateSpecification = (LaunchTemplate -> Maybe LaunchTemplateSpecification)
-> (LaunchTemplate
    -> Maybe LaunchTemplateSpecification -> LaunchTemplate)
-> Lens
     LaunchTemplate
     LaunchTemplate
     (Maybe LaunchTemplateSpecification)
     (Maybe LaunchTemplateSpecification)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LaunchTemplate' {Maybe LaunchTemplateSpecification
launchTemplateSpecification :: Maybe LaunchTemplateSpecification
$sel:launchTemplateSpecification:LaunchTemplate' :: LaunchTemplate -> Maybe LaunchTemplateSpecification
launchTemplateSpecification} -> Maybe LaunchTemplateSpecification
launchTemplateSpecification) (\s :: LaunchTemplate
s@LaunchTemplate' {} Maybe LaunchTemplateSpecification
a -> LaunchTemplate
s {$sel:launchTemplateSpecification:LaunchTemplate' :: Maybe LaunchTemplateSpecification
launchTemplateSpecification = Maybe LaunchTemplateSpecification
a} :: LaunchTemplate)

instance Core.FromXML LaunchTemplate where
  parseXML :: [Node] -> Either String LaunchTemplate
parseXML [Node]
x =
    Maybe [LaunchTemplateOverrides]
-> Maybe LaunchTemplateSpecification -> LaunchTemplate
LaunchTemplate'
      (Maybe [LaunchTemplateOverrides]
 -> Maybe LaunchTemplateSpecification -> LaunchTemplate)
-> Either String (Maybe [LaunchTemplateOverrides])
-> Either
     String (Maybe LaunchTemplateSpecification -> LaunchTemplate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Overrides" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [LaunchTemplateOverrides]))
-> Either String (Maybe [LaunchTemplateOverrides])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [LaunchTemplateOverrides])
-> [Node] -> Either String (Maybe [LaunchTemplateOverrides])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [LaunchTemplateOverrides]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either String (Maybe LaunchTemplateSpecification -> LaunchTemplate)
-> Either String (Maybe LaunchTemplateSpecification)
-> Either String LaunchTemplate
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 LaunchTemplate

instance Prelude.NFData LaunchTemplate

instance Core.ToQuery LaunchTemplate where
  toQuery :: LaunchTemplate -> QueryString
toQuery LaunchTemplate' {Maybe [LaunchTemplateOverrides]
Maybe LaunchTemplateSpecification
launchTemplateSpecification :: Maybe LaunchTemplateSpecification
overrides :: Maybe [LaunchTemplateOverrides]
$sel:launchTemplateSpecification:LaunchTemplate' :: LaunchTemplate -> Maybe LaunchTemplateSpecification
$sel:overrides:LaunchTemplate' :: LaunchTemplate -> Maybe [LaunchTemplateOverrides]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Overrides"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [LaunchTemplateOverrides] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([LaunchTemplateOverrides] -> QueryString)
-> Maybe [LaunchTemplateOverrides] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [LaunchTemplateOverrides]
overrides),
        ByteString
"LaunchTemplateSpecification"
          ByteString -> Maybe LaunchTemplateSpecification -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe LaunchTemplateSpecification
launchTemplateSpecification
      ]