{-# 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.ImageBuilder.Types.InstanceConfiguration
-- 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.ImageBuilder.Types.InstanceConfiguration where

import qualified Amazonka.Core as Core
import Amazonka.ImageBuilder.Types.InstanceBlockDeviceMapping
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines a custom base AMI and block device mapping configurations of an
-- instance used for building and testing container images.
--
-- /See:/ 'newInstanceConfiguration' smart constructor.
data InstanceConfiguration = InstanceConfiguration'
  { -- | The AMI ID to use as the base image for a container build and test
    -- instance. If not specified, Image Builder will use the appropriate
    -- ECS-optimized AMI as a base image.
    InstanceConfiguration -> Maybe Text
image :: Prelude.Maybe Prelude.Text,
    -- | Defines the block devices to attach for building an instance from this
    -- Image Builder AMI.
    InstanceConfiguration -> Maybe [InstanceBlockDeviceMapping]
blockDeviceMappings :: Prelude.Maybe [InstanceBlockDeviceMapping]
  }
  deriving (InstanceConfiguration -> InstanceConfiguration -> Bool
(InstanceConfiguration -> InstanceConfiguration -> Bool)
-> (InstanceConfiguration -> InstanceConfiguration -> Bool)
-> Eq InstanceConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceConfiguration -> InstanceConfiguration -> Bool
$c/= :: InstanceConfiguration -> InstanceConfiguration -> Bool
== :: InstanceConfiguration -> InstanceConfiguration -> Bool
$c== :: InstanceConfiguration -> InstanceConfiguration -> Bool
Prelude.Eq, ReadPrec [InstanceConfiguration]
ReadPrec InstanceConfiguration
Int -> ReadS InstanceConfiguration
ReadS [InstanceConfiguration]
(Int -> ReadS InstanceConfiguration)
-> ReadS [InstanceConfiguration]
-> ReadPrec InstanceConfiguration
-> ReadPrec [InstanceConfiguration]
-> Read InstanceConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceConfiguration]
$creadListPrec :: ReadPrec [InstanceConfiguration]
readPrec :: ReadPrec InstanceConfiguration
$creadPrec :: ReadPrec InstanceConfiguration
readList :: ReadS [InstanceConfiguration]
$creadList :: ReadS [InstanceConfiguration]
readsPrec :: Int -> ReadS InstanceConfiguration
$creadsPrec :: Int -> ReadS InstanceConfiguration
Prelude.Read, Int -> InstanceConfiguration -> ShowS
[InstanceConfiguration] -> ShowS
InstanceConfiguration -> String
(Int -> InstanceConfiguration -> ShowS)
-> (InstanceConfiguration -> String)
-> ([InstanceConfiguration] -> ShowS)
-> Show InstanceConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceConfiguration] -> ShowS
$cshowList :: [InstanceConfiguration] -> ShowS
show :: InstanceConfiguration -> String
$cshow :: InstanceConfiguration -> String
showsPrec :: Int -> InstanceConfiguration -> ShowS
$cshowsPrec :: Int -> InstanceConfiguration -> ShowS
Prelude.Show, (forall x. InstanceConfiguration -> Rep InstanceConfiguration x)
-> (forall x. Rep InstanceConfiguration x -> InstanceConfiguration)
-> Generic InstanceConfiguration
forall x. Rep InstanceConfiguration x -> InstanceConfiguration
forall x. InstanceConfiguration -> Rep InstanceConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceConfiguration x -> InstanceConfiguration
$cfrom :: forall x. InstanceConfiguration -> Rep InstanceConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'InstanceConfiguration' 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:
--
-- 'image', 'instanceConfiguration_image' - The AMI ID to use as the base image for a container build and test
-- instance. If not specified, Image Builder will use the appropriate
-- ECS-optimized AMI as a base image.
--
-- 'blockDeviceMappings', 'instanceConfiguration_blockDeviceMappings' - Defines the block devices to attach for building an instance from this
-- Image Builder AMI.
newInstanceConfiguration ::
  InstanceConfiguration
newInstanceConfiguration :: InstanceConfiguration
newInstanceConfiguration =
  InstanceConfiguration' :: Maybe Text
-> Maybe [InstanceBlockDeviceMapping] -> InstanceConfiguration
InstanceConfiguration'
    { $sel:image:InstanceConfiguration' :: Maybe Text
image = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:blockDeviceMappings:InstanceConfiguration' :: Maybe [InstanceBlockDeviceMapping]
blockDeviceMappings = Maybe [InstanceBlockDeviceMapping]
forall a. Maybe a
Prelude.Nothing
    }

-- | The AMI ID to use as the base image for a container build and test
-- instance. If not specified, Image Builder will use the appropriate
-- ECS-optimized AMI as a base image.
instanceConfiguration_image :: Lens.Lens' InstanceConfiguration (Prelude.Maybe Prelude.Text)
instanceConfiguration_image :: (Maybe Text -> f (Maybe Text))
-> InstanceConfiguration -> f InstanceConfiguration
instanceConfiguration_image = (InstanceConfiguration -> Maybe Text)
-> (InstanceConfiguration -> Maybe Text -> InstanceConfiguration)
-> Lens
     InstanceConfiguration
     InstanceConfiguration
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceConfiguration' {Maybe Text
image :: Maybe Text
$sel:image:InstanceConfiguration' :: InstanceConfiguration -> Maybe Text
image} -> Maybe Text
image) (\s :: InstanceConfiguration
s@InstanceConfiguration' {} Maybe Text
a -> InstanceConfiguration
s {$sel:image:InstanceConfiguration' :: Maybe Text
image = Maybe Text
a} :: InstanceConfiguration)

-- | Defines the block devices to attach for building an instance from this
-- Image Builder AMI.
instanceConfiguration_blockDeviceMappings :: Lens.Lens' InstanceConfiguration (Prelude.Maybe [InstanceBlockDeviceMapping])
instanceConfiguration_blockDeviceMappings :: (Maybe [InstanceBlockDeviceMapping]
 -> f (Maybe [InstanceBlockDeviceMapping]))
-> InstanceConfiguration -> f InstanceConfiguration
instanceConfiguration_blockDeviceMappings = (InstanceConfiguration -> Maybe [InstanceBlockDeviceMapping])
-> (InstanceConfiguration
    -> Maybe [InstanceBlockDeviceMapping] -> InstanceConfiguration)
-> Lens
     InstanceConfiguration
     InstanceConfiguration
     (Maybe [InstanceBlockDeviceMapping])
     (Maybe [InstanceBlockDeviceMapping])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceConfiguration' {Maybe [InstanceBlockDeviceMapping]
blockDeviceMappings :: Maybe [InstanceBlockDeviceMapping]
$sel:blockDeviceMappings:InstanceConfiguration' :: InstanceConfiguration -> Maybe [InstanceBlockDeviceMapping]
blockDeviceMappings} -> Maybe [InstanceBlockDeviceMapping]
blockDeviceMappings) (\s :: InstanceConfiguration
s@InstanceConfiguration' {} Maybe [InstanceBlockDeviceMapping]
a -> InstanceConfiguration
s {$sel:blockDeviceMappings:InstanceConfiguration' :: Maybe [InstanceBlockDeviceMapping]
blockDeviceMappings = Maybe [InstanceBlockDeviceMapping]
a} :: InstanceConfiguration) ((Maybe [InstanceBlockDeviceMapping]
  -> f (Maybe [InstanceBlockDeviceMapping]))
 -> InstanceConfiguration -> f InstanceConfiguration)
-> ((Maybe [InstanceBlockDeviceMapping]
     -> f (Maybe [InstanceBlockDeviceMapping]))
    -> Maybe [InstanceBlockDeviceMapping]
    -> f (Maybe [InstanceBlockDeviceMapping]))
-> (Maybe [InstanceBlockDeviceMapping]
    -> f (Maybe [InstanceBlockDeviceMapping]))
-> InstanceConfiguration
-> f InstanceConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [InstanceBlockDeviceMapping]
  [InstanceBlockDeviceMapping]
  [InstanceBlockDeviceMapping]
  [InstanceBlockDeviceMapping]
-> Iso
     (Maybe [InstanceBlockDeviceMapping])
     (Maybe [InstanceBlockDeviceMapping])
     (Maybe [InstanceBlockDeviceMapping])
     (Maybe [InstanceBlockDeviceMapping])
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
  [InstanceBlockDeviceMapping]
  [InstanceBlockDeviceMapping]
  [InstanceBlockDeviceMapping]
  [InstanceBlockDeviceMapping]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON InstanceConfiguration where
  parseJSON :: Value -> Parser InstanceConfiguration
parseJSON =
    String
-> (Object -> Parser InstanceConfiguration)
-> Value
-> Parser InstanceConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InstanceConfiguration"
      ( \Object
x ->
          Maybe Text
-> Maybe [InstanceBlockDeviceMapping] -> InstanceConfiguration
InstanceConfiguration'
            (Maybe Text
 -> Maybe [InstanceBlockDeviceMapping] -> InstanceConfiguration)
-> Parser (Maybe Text)
-> Parser
     (Maybe [InstanceBlockDeviceMapping] -> InstanceConfiguration)
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
"image")
            Parser
  (Maybe [InstanceBlockDeviceMapping] -> InstanceConfiguration)
-> Parser (Maybe [InstanceBlockDeviceMapping])
-> Parser InstanceConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object
-> Text -> Parser (Maybe (Maybe [InstanceBlockDeviceMapping]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"blockDeviceMappings"
                            Parser (Maybe (Maybe [InstanceBlockDeviceMapping]))
-> Maybe [InstanceBlockDeviceMapping]
-> Parser (Maybe [InstanceBlockDeviceMapping])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [InstanceBlockDeviceMapping]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable InstanceConfiguration

instance Prelude.NFData InstanceConfiguration

instance Core.ToJSON InstanceConfiguration where
  toJSON :: InstanceConfiguration -> Value
toJSON InstanceConfiguration' {Maybe [InstanceBlockDeviceMapping]
Maybe Text
blockDeviceMappings :: Maybe [InstanceBlockDeviceMapping]
image :: Maybe Text
$sel:blockDeviceMappings:InstanceConfiguration' :: InstanceConfiguration -> Maybe [InstanceBlockDeviceMapping]
$sel:image:InstanceConfiguration' :: InstanceConfiguration -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"image" 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
image,
            (Text
"blockDeviceMappings" Text -> [InstanceBlockDeviceMapping] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([InstanceBlockDeviceMapping] -> Pair)
-> Maybe [InstanceBlockDeviceMapping] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [InstanceBlockDeviceMapping]
blockDeviceMappings
          ]
      )