{-# 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.Batch.Types.Ec2Configuration
-- 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.Batch.Types.Ec2Configuration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides information used to select Amazon Machine Images (AMIs) for
-- instances in the compute environment. If @Ec2Configuration@ isn\'t
-- specified, the default is currently @ECS_AL1@
-- (<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#alami Amazon Linux>)
-- for non-GPU, non AWSGraviton instances. Starting on March 31, 2021, this
-- default will be changing to @ECS_AL2@
-- (<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#al2ami Amazon Linux 2>).
--
-- This object isn\'t applicable to jobs that are running on Fargate
-- resources.
--
-- /See:/ 'newEc2Configuration' smart constructor.
data Ec2Configuration = Ec2Configuration'
  { -- | The AMI ID used for instances launched in the compute environment that
    -- match the image type. This setting overrides the @imageId@ set in the
    -- @computeResource@ object.
    Ec2Configuration -> Maybe Text
imageIdOverride :: Prelude.Maybe Prelude.Text,
    -- | The image type to match with the instance type to select an AMI. If the
    -- @imageIdOverride@ parameter isn\'t specified, then a recent
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html Amazon ECS-optimized AMI>
    -- (@ECS_AL1@) is used. Starting on March 31, 2021, this default will be
    -- changing to @ECS_AL2@
    -- (<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#al2ami Amazon Linux 2>).
    --
    -- [ECS_AL2]
    --     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#al2ami Amazon Linux 2>−
    --     Default for all Amazon Web Services Graviton-based instance families
    --     (for example, @C6g@, @M6g@, @R6g@, and @T4g@) and can be used for
    --     all non-GPU instance types.
    --
    -- [ECS_AL2_NVIDIA]
    --     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#gpuami Amazon Linux 2 (GPU)>−Default
    --     for all GPU instance families (for example @P4@ and @G4@) and can be
    --     used for all non Amazon Web Services Graviton-based instance types.
    --
    -- [ECS_AL1]
    --     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#alami Amazon Linux>−Default
    --     for all non-GPU, non Amazon Web Services Graviton instance families.
    --     Amazon Linux is reaching the end-of-life of standard support. For
    --     more information, see
    --     <http://aws.amazon.com/amazon-linux-ami/ Amazon Linux AMI>.
    Ec2Configuration -> Text
imageType :: Prelude.Text
  }
  deriving (Ec2Configuration -> Ec2Configuration -> Bool
(Ec2Configuration -> Ec2Configuration -> Bool)
-> (Ec2Configuration -> Ec2Configuration -> Bool)
-> Eq Ec2Configuration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ec2Configuration -> Ec2Configuration -> Bool
$c/= :: Ec2Configuration -> Ec2Configuration -> Bool
== :: Ec2Configuration -> Ec2Configuration -> Bool
$c== :: Ec2Configuration -> Ec2Configuration -> Bool
Prelude.Eq, ReadPrec [Ec2Configuration]
ReadPrec Ec2Configuration
Int -> ReadS Ec2Configuration
ReadS [Ec2Configuration]
(Int -> ReadS Ec2Configuration)
-> ReadS [Ec2Configuration]
-> ReadPrec Ec2Configuration
-> ReadPrec [Ec2Configuration]
-> Read Ec2Configuration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ec2Configuration]
$creadListPrec :: ReadPrec [Ec2Configuration]
readPrec :: ReadPrec Ec2Configuration
$creadPrec :: ReadPrec Ec2Configuration
readList :: ReadS [Ec2Configuration]
$creadList :: ReadS [Ec2Configuration]
readsPrec :: Int -> ReadS Ec2Configuration
$creadsPrec :: Int -> ReadS Ec2Configuration
Prelude.Read, Int -> Ec2Configuration -> ShowS
[Ec2Configuration] -> ShowS
Ec2Configuration -> String
(Int -> Ec2Configuration -> ShowS)
-> (Ec2Configuration -> String)
-> ([Ec2Configuration] -> ShowS)
-> Show Ec2Configuration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ec2Configuration] -> ShowS
$cshowList :: [Ec2Configuration] -> ShowS
show :: Ec2Configuration -> String
$cshow :: Ec2Configuration -> String
showsPrec :: Int -> Ec2Configuration -> ShowS
$cshowsPrec :: Int -> Ec2Configuration -> ShowS
Prelude.Show, (forall x. Ec2Configuration -> Rep Ec2Configuration x)
-> (forall x. Rep Ec2Configuration x -> Ec2Configuration)
-> Generic Ec2Configuration
forall x. Rep Ec2Configuration x -> Ec2Configuration
forall x. Ec2Configuration -> Rep Ec2Configuration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Ec2Configuration x -> Ec2Configuration
$cfrom :: forall x. Ec2Configuration -> Rep Ec2Configuration x
Prelude.Generic)

-- |
-- Create a value of 'Ec2Configuration' 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:
--
-- 'imageIdOverride', 'ec2Configuration_imageIdOverride' - The AMI ID used for instances launched in the compute environment that
-- match the image type. This setting overrides the @imageId@ set in the
-- @computeResource@ object.
--
-- 'imageType', 'ec2Configuration_imageType' - The image type to match with the instance type to select an AMI. If the
-- @imageIdOverride@ parameter isn\'t specified, then a recent
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html Amazon ECS-optimized AMI>
-- (@ECS_AL1@) is used. Starting on March 31, 2021, this default will be
-- changing to @ECS_AL2@
-- (<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#al2ami Amazon Linux 2>).
--
-- [ECS_AL2]
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#al2ami Amazon Linux 2>−
--     Default for all Amazon Web Services Graviton-based instance families
--     (for example, @C6g@, @M6g@, @R6g@, and @T4g@) and can be used for
--     all non-GPU instance types.
--
-- [ECS_AL2_NVIDIA]
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#gpuami Amazon Linux 2 (GPU)>−Default
--     for all GPU instance families (for example @P4@ and @G4@) and can be
--     used for all non Amazon Web Services Graviton-based instance types.
--
-- [ECS_AL1]
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#alami Amazon Linux>−Default
--     for all non-GPU, non Amazon Web Services Graviton instance families.
--     Amazon Linux is reaching the end-of-life of standard support. For
--     more information, see
--     <http://aws.amazon.com/amazon-linux-ami/ Amazon Linux AMI>.
newEc2Configuration ::
  -- | 'imageType'
  Prelude.Text ->
  Ec2Configuration
newEc2Configuration :: Text -> Ec2Configuration
newEc2Configuration Text
pImageType_ =
  Ec2Configuration' :: Maybe Text -> Text -> Ec2Configuration
Ec2Configuration'
    { $sel:imageIdOverride:Ec2Configuration' :: Maybe Text
imageIdOverride =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:imageType:Ec2Configuration' :: Text
imageType = Text
pImageType_
    }

-- | The AMI ID used for instances launched in the compute environment that
-- match the image type. This setting overrides the @imageId@ set in the
-- @computeResource@ object.
ec2Configuration_imageIdOverride :: Lens.Lens' Ec2Configuration (Prelude.Maybe Prelude.Text)
ec2Configuration_imageIdOverride :: (Maybe Text -> f (Maybe Text))
-> Ec2Configuration -> f Ec2Configuration
ec2Configuration_imageIdOverride = (Ec2Configuration -> Maybe Text)
-> (Ec2Configuration -> Maybe Text -> Ec2Configuration)
-> Lens Ec2Configuration Ec2Configuration (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ec2Configuration' {Maybe Text
imageIdOverride :: Maybe Text
$sel:imageIdOverride:Ec2Configuration' :: Ec2Configuration -> Maybe Text
imageIdOverride} -> Maybe Text
imageIdOverride) (\s :: Ec2Configuration
s@Ec2Configuration' {} Maybe Text
a -> Ec2Configuration
s {$sel:imageIdOverride:Ec2Configuration' :: Maybe Text
imageIdOverride = Maybe Text
a} :: Ec2Configuration)

-- | The image type to match with the instance type to select an AMI. If the
-- @imageIdOverride@ parameter isn\'t specified, then a recent
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html Amazon ECS-optimized AMI>
-- (@ECS_AL1@) is used. Starting on March 31, 2021, this default will be
-- changing to @ECS_AL2@
-- (<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#al2ami Amazon Linux 2>).
--
-- [ECS_AL2]
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#al2ami Amazon Linux 2>−
--     Default for all Amazon Web Services Graviton-based instance families
--     (for example, @C6g@, @M6g@, @R6g@, and @T4g@) and can be used for
--     all non-GPU instance types.
--
-- [ECS_AL2_NVIDIA]
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#gpuami Amazon Linux 2 (GPU)>−Default
--     for all GPU instance families (for example @P4@ and @G4@) and can be
--     used for all non Amazon Web Services Graviton-based instance types.
--
-- [ECS_AL1]
--     <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html#alami Amazon Linux>−Default
--     for all non-GPU, non Amazon Web Services Graviton instance families.
--     Amazon Linux is reaching the end-of-life of standard support. For
--     more information, see
--     <http://aws.amazon.com/amazon-linux-ami/ Amazon Linux AMI>.
ec2Configuration_imageType :: Lens.Lens' Ec2Configuration Prelude.Text
ec2Configuration_imageType :: (Text -> f Text) -> Ec2Configuration -> f Ec2Configuration
ec2Configuration_imageType = (Ec2Configuration -> Text)
-> (Ec2Configuration -> Text -> Ec2Configuration)
-> Lens Ec2Configuration Ec2Configuration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ec2Configuration' {Text
imageType :: Text
$sel:imageType:Ec2Configuration' :: Ec2Configuration -> Text
imageType} -> Text
imageType) (\s :: Ec2Configuration
s@Ec2Configuration' {} Text
a -> Ec2Configuration
s {$sel:imageType:Ec2Configuration' :: Text
imageType = Text
a} :: Ec2Configuration)

instance Core.FromJSON Ec2Configuration where
  parseJSON :: Value -> Parser Ec2Configuration
parseJSON =
    String
-> (Object -> Parser Ec2Configuration)
-> Value
-> Parser Ec2Configuration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Ec2Configuration"
      ( \Object
x ->
          Maybe Text -> Text -> Ec2Configuration
Ec2Configuration'
            (Maybe Text -> Text -> Ec2Configuration)
-> Parser (Maybe Text) -> Parser (Text -> Ec2Configuration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"imageIdOverride")
            Parser (Text -> Ec2Configuration)
-> Parser Text -> Parser Ec2Configuration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"imageType")
      )

instance Prelude.Hashable Ec2Configuration

instance Prelude.NFData Ec2Configuration

instance Core.ToJSON Ec2Configuration where
  toJSON :: Ec2Configuration -> Value
toJSON Ec2Configuration' {Maybe Text
Text
imageType :: Text
imageIdOverride :: Maybe Text
$sel:imageType:Ec2Configuration' :: Ec2Configuration -> Text
$sel:imageIdOverride:Ec2Configuration' :: Ec2Configuration -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"imageIdOverride" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
imageIdOverride,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"imageType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
imageType)
          ]
      )