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

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

-- | Defines block device mappings for the instance used to configure your
-- image.
--
-- /See:/ 'newInstanceBlockDeviceMapping' smart constructor.
data InstanceBlockDeviceMapping = InstanceBlockDeviceMapping'
  { -- | Use to manage instance ephemeral devices.
    InstanceBlockDeviceMapping -> Maybe Text
virtualName :: Prelude.Maybe Prelude.Text,
    -- | Use to remove a mapping from the base image.
    InstanceBlockDeviceMapping -> Maybe Text
noDevice :: Prelude.Maybe Prelude.Text,
    -- | Use to manage Amazon EBS-specific configuration for this mapping.
    InstanceBlockDeviceMapping
-> Maybe EbsInstanceBlockDeviceSpecification
ebs :: Prelude.Maybe EbsInstanceBlockDeviceSpecification,
    -- | The device to which these mappings apply.
    InstanceBlockDeviceMapping -> Maybe Text
deviceName :: Prelude.Maybe Prelude.Text
  }
  deriving (InstanceBlockDeviceMapping -> InstanceBlockDeviceMapping -> Bool
(InstanceBlockDeviceMapping -> InstanceBlockDeviceMapping -> Bool)
-> (InstanceBlockDeviceMapping
    -> InstanceBlockDeviceMapping -> Bool)
-> Eq InstanceBlockDeviceMapping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceBlockDeviceMapping -> InstanceBlockDeviceMapping -> Bool
$c/= :: InstanceBlockDeviceMapping -> InstanceBlockDeviceMapping -> Bool
== :: InstanceBlockDeviceMapping -> InstanceBlockDeviceMapping -> Bool
$c== :: InstanceBlockDeviceMapping -> InstanceBlockDeviceMapping -> Bool
Prelude.Eq, ReadPrec [InstanceBlockDeviceMapping]
ReadPrec InstanceBlockDeviceMapping
Int -> ReadS InstanceBlockDeviceMapping
ReadS [InstanceBlockDeviceMapping]
(Int -> ReadS InstanceBlockDeviceMapping)
-> ReadS [InstanceBlockDeviceMapping]
-> ReadPrec InstanceBlockDeviceMapping
-> ReadPrec [InstanceBlockDeviceMapping]
-> Read InstanceBlockDeviceMapping
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceBlockDeviceMapping]
$creadListPrec :: ReadPrec [InstanceBlockDeviceMapping]
readPrec :: ReadPrec InstanceBlockDeviceMapping
$creadPrec :: ReadPrec InstanceBlockDeviceMapping
readList :: ReadS [InstanceBlockDeviceMapping]
$creadList :: ReadS [InstanceBlockDeviceMapping]
readsPrec :: Int -> ReadS InstanceBlockDeviceMapping
$creadsPrec :: Int -> ReadS InstanceBlockDeviceMapping
Prelude.Read, Int -> InstanceBlockDeviceMapping -> ShowS
[InstanceBlockDeviceMapping] -> ShowS
InstanceBlockDeviceMapping -> String
(Int -> InstanceBlockDeviceMapping -> ShowS)
-> (InstanceBlockDeviceMapping -> String)
-> ([InstanceBlockDeviceMapping] -> ShowS)
-> Show InstanceBlockDeviceMapping
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceBlockDeviceMapping] -> ShowS
$cshowList :: [InstanceBlockDeviceMapping] -> ShowS
show :: InstanceBlockDeviceMapping -> String
$cshow :: InstanceBlockDeviceMapping -> String
showsPrec :: Int -> InstanceBlockDeviceMapping -> ShowS
$cshowsPrec :: Int -> InstanceBlockDeviceMapping -> ShowS
Prelude.Show, (forall x.
 InstanceBlockDeviceMapping -> Rep InstanceBlockDeviceMapping x)
-> (forall x.
    Rep InstanceBlockDeviceMapping x -> InstanceBlockDeviceMapping)
-> Generic InstanceBlockDeviceMapping
forall x.
Rep InstanceBlockDeviceMapping x -> InstanceBlockDeviceMapping
forall x.
InstanceBlockDeviceMapping -> Rep InstanceBlockDeviceMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep InstanceBlockDeviceMapping x -> InstanceBlockDeviceMapping
$cfrom :: forall x.
InstanceBlockDeviceMapping -> Rep InstanceBlockDeviceMapping x
Prelude.Generic)

-- |
-- Create a value of 'InstanceBlockDeviceMapping' 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:
--
-- 'virtualName', 'instanceBlockDeviceMapping_virtualName' - Use to manage instance ephemeral devices.
--
-- 'noDevice', 'instanceBlockDeviceMapping_noDevice' - Use to remove a mapping from the base image.
--
-- 'ebs', 'instanceBlockDeviceMapping_ebs' - Use to manage Amazon EBS-specific configuration for this mapping.
--
-- 'deviceName', 'instanceBlockDeviceMapping_deviceName' - The device to which these mappings apply.
newInstanceBlockDeviceMapping ::
  InstanceBlockDeviceMapping
newInstanceBlockDeviceMapping :: InstanceBlockDeviceMapping
newInstanceBlockDeviceMapping =
  InstanceBlockDeviceMapping' :: Maybe Text
-> Maybe Text
-> Maybe EbsInstanceBlockDeviceSpecification
-> Maybe Text
-> InstanceBlockDeviceMapping
InstanceBlockDeviceMapping'
    { $sel:virtualName:InstanceBlockDeviceMapping' :: Maybe Text
virtualName =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:noDevice:InstanceBlockDeviceMapping' :: Maybe Text
noDevice = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:ebs:InstanceBlockDeviceMapping' :: Maybe EbsInstanceBlockDeviceSpecification
ebs = Maybe EbsInstanceBlockDeviceSpecification
forall a. Maybe a
Prelude.Nothing,
      $sel:deviceName:InstanceBlockDeviceMapping' :: Maybe Text
deviceName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Use to manage instance ephemeral devices.
instanceBlockDeviceMapping_virtualName :: Lens.Lens' InstanceBlockDeviceMapping (Prelude.Maybe Prelude.Text)
instanceBlockDeviceMapping_virtualName :: (Maybe Text -> f (Maybe Text))
-> InstanceBlockDeviceMapping -> f InstanceBlockDeviceMapping
instanceBlockDeviceMapping_virtualName = (InstanceBlockDeviceMapping -> Maybe Text)
-> (InstanceBlockDeviceMapping
    -> Maybe Text -> InstanceBlockDeviceMapping)
-> Lens
     InstanceBlockDeviceMapping
     InstanceBlockDeviceMapping
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceBlockDeviceMapping' {Maybe Text
virtualName :: Maybe Text
$sel:virtualName:InstanceBlockDeviceMapping' :: InstanceBlockDeviceMapping -> Maybe Text
virtualName} -> Maybe Text
virtualName) (\s :: InstanceBlockDeviceMapping
s@InstanceBlockDeviceMapping' {} Maybe Text
a -> InstanceBlockDeviceMapping
s {$sel:virtualName:InstanceBlockDeviceMapping' :: Maybe Text
virtualName = Maybe Text
a} :: InstanceBlockDeviceMapping)

-- | Use to remove a mapping from the base image.
instanceBlockDeviceMapping_noDevice :: Lens.Lens' InstanceBlockDeviceMapping (Prelude.Maybe Prelude.Text)
instanceBlockDeviceMapping_noDevice :: (Maybe Text -> f (Maybe Text))
-> InstanceBlockDeviceMapping -> f InstanceBlockDeviceMapping
instanceBlockDeviceMapping_noDevice = (InstanceBlockDeviceMapping -> Maybe Text)
-> (InstanceBlockDeviceMapping
    -> Maybe Text -> InstanceBlockDeviceMapping)
-> Lens
     InstanceBlockDeviceMapping
     InstanceBlockDeviceMapping
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceBlockDeviceMapping' {Maybe Text
noDevice :: Maybe Text
$sel:noDevice:InstanceBlockDeviceMapping' :: InstanceBlockDeviceMapping -> Maybe Text
noDevice} -> Maybe Text
noDevice) (\s :: InstanceBlockDeviceMapping
s@InstanceBlockDeviceMapping' {} Maybe Text
a -> InstanceBlockDeviceMapping
s {$sel:noDevice:InstanceBlockDeviceMapping' :: Maybe Text
noDevice = Maybe Text
a} :: InstanceBlockDeviceMapping)

-- | Use to manage Amazon EBS-specific configuration for this mapping.
instanceBlockDeviceMapping_ebs :: Lens.Lens' InstanceBlockDeviceMapping (Prelude.Maybe EbsInstanceBlockDeviceSpecification)
instanceBlockDeviceMapping_ebs :: (Maybe EbsInstanceBlockDeviceSpecification
 -> f (Maybe EbsInstanceBlockDeviceSpecification))
-> InstanceBlockDeviceMapping -> f InstanceBlockDeviceMapping
instanceBlockDeviceMapping_ebs = (InstanceBlockDeviceMapping
 -> Maybe EbsInstanceBlockDeviceSpecification)
-> (InstanceBlockDeviceMapping
    -> Maybe EbsInstanceBlockDeviceSpecification
    -> InstanceBlockDeviceMapping)
-> Lens
     InstanceBlockDeviceMapping
     InstanceBlockDeviceMapping
     (Maybe EbsInstanceBlockDeviceSpecification)
     (Maybe EbsInstanceBlockDeviceSpecification)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceBlockDeviceMapping' {Maybe EbsInstanceBlockDeviceSpecification
ebs :: Maybe EbsInstanceBlockDeviceSpecification
$sel:ebs:InstanceBlockDeviceMapping' :: InstanceBlockDeviceMapping
-> Maybe EbsInstanceBlockDeviceSpecification
ebs} -> Maybe EbsInstanceBlockDeviceSpecification
ebs) (\s :: InstanceBlockDeviceMapping
s@InstanceBlockDeviceMapping' {} Maybe EbsInstanceBlockDeviceSpecification
a -> InstanceBlockDeviceMapping
s {$sel:ebs:InstanceBlockDeviceMapping' :: Maybe EbsInstanceBlockDeviceSpecification
ebs = Maybe EbsInstanceBlockDeviceSpecification
a} :: InstanceBlockDeviceMapping)

-- | The device to which these mappings apply.
instanceBlockDeviceMapping_deviceName :: Lens.Lens' InstanceBlockDeviceMapping (Prelude.Maybe Prelude.Text)
instanceBlockDeviceMapping_deviceName :: (Maybe Text -> f (Maybe Text))
-> InstanceBlockDeviceMapping -> f InstanceBlockDeviceMapping
instanceBlockDeviceMapping_deviceName = (InstanceBlockDeviceMapping -> Maybe Text)
-> (InstanceBlockDeviceMapping
    -> Maybe Text -> InstanceBlockDeviceMapping)
-> Lens
     InstanceBlockDeviceMapping
     InstanceBlockDeviceMapping
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceBlockDeviceMapping' {Maybe Text
deviceName :: Maybe Text
$sel:deviceName:InstanceBlockDeviceMapping' :: InstanceBlockDeviceMapping -> Maybe Text
deviceName} -> Maybe Text
deviceName) (\s :: InstanceBlockDeviceMapping
s@InstanceBlockDeviceMapping' {} Maybe Text
a -> InstanceBlockDeviceMapping
s {$sel:deviceName:InstanceBlockDeviceMapping' :: Maybe Text
deviceName = Maybe Text
a} :: InstanceBlockDeviceMapping)

instance Core.FromJSON InstanceBlockDeviceMapping where
  parseJSON :: Value -> Parser InstanceBlockDeviceMapping
parseJSON =
    String
-> (Object -> Parser InstanceBlockDeviceMapping)
-> Value
-> Parser InstanceBlockDeviceMapping
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InstanceBlockDeviceMapping"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe EbsInstanceBlockDeviceSpecification
-> Maybe Text
-> InstanceBlockDeviceMapping
InstanceBlockDeviceMapping'
            (Maybe Text
 -> Maybe Text
 -> Maybe EbsInstanceBlockDeviceSpecification
 -> Maybe Text
 -> InstanceBlockDeviceMapping)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe EbsInstanceBlockDeviceSpecification
      -> Maybe Text
      -> InstanceBlockDeviceMapping)
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
"virtualName")
            Parser
  (Maybe Text
   -> Maybe EbsInstanceBlockDeviceSpecification
   -> Maybe Text
   -> InstanceBlockDeviceMapping)
-> Parser (Maybe Text)
-> Parser
     (Maybe EbsInstanceBlockDeviceSpecification
      -> Maybe Text -> InstanceBlockDeviceMapping)
forall (f :: * -> *) a b. Applicative f => 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
"noDevice")
            Parser
  (Maybe EbsInstanceBlockDeviceSpecification
   -> Maybe Text -> InstanceBlockDeviceMapping)
-> Parser (Maybe EbsInstanceBlockDeviceSpecification)
-> Parser (Maybe Text -> InstanceBlockDeviceMapping)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe EbsInstanceBlockDeviceSpecification)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ebs")
            Parser (Maybe Text -> InstanceBlockDeviceMapping)
-> Parser (Maybe Text) -> Parser InstanceBlockDeviceMapping
forall (f :: * -> *) a b. Applicative f => 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
"deviceName")
      )

instance Prelude.Hashable InstanceBlockDeviceMapping

instance Prelude.NFData InstanceBlockDeviceMapping

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