{-# 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.OpsWorks.Types.BlockDeviceMapping
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.OpsWorks.Types.BlockDeviceMapping where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.OpsWorks.Types.EbsBlockDevice
import qualified Amazonka.Prelude as Prelude

-- | Describes a block device mapping. This data type maps directly to the
-- Amazon EC2
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html BlockDeviceMapping>
-- data type.
--
-- /See:/ 'newBlockDeviceMapping' smart constructor.
data BlockDeviceMapping = BlockDeviceMapping'
  { -- | The device name that is exposed to the instance, such as @\/dev\/sdh@.
    -- For the root device, you can use the explicit device name or you can set
    -- this parameter to @ROOT_DEVICE@ and AWS OpsWorks Stacks will provide the
    -- correct device name.
    BlockDeviceMapping -> Maybe Text
deviceName :: Prelude.Maybe Prelude.Text,
    -- | An @EBSBlockDevice@ that defines how to configure an Amazon EBS volume
    -- when the instance is launched.
    BlockDeviceMapping -> Maybe EbsBlockDevice
ebs :: Prelude.Maybe EbsBlockDevice,
    -- | Suppresses the specified device included in the AMI\'s block device
    -- mapping.
    BlockDeviceMapping -> Maybe Text
noDevice :: Prelude.Maybe Prelude.Text,
    -- | The virtual device name. For more information, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html BlockDeviceMapping>.
    BlockDeviceMapping -> Maybe Text
virtualName :: Prelude.Maybe Prelude.Text
  }
  deriving (BlockDeviceMapping -> BlockDeviceMapping -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlockDeviceMapping -> BlockDeviceMapping -> Bool
$c/= :: BlockDeviceMapping -> BlockDeviceMapping -> Bool
== :: BlockDeviceMapping -> BlockDeviceMapping -> Bool
$c== :: BlockDeviceMapping -> BlockDeviceMapping -> Bool
Prelude.Eq, ReadPrec [BlockDeviceMapping]
ReadPrec BlockDeviceMapping
Int -> ReadS BlockDeviceMapping
ReadS [BlockDeviceMapping]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BlockDeviceMapping]
$creadListPrec :: ReadPrec [BlockDeviceMapping]
readPrec :: ReadPrec BlockDeviceMapping
$creadPrec :: ReadPrec BlockDeviceMapping
readList :: ReadS [BlockDeviceMapping]
$creadList :: ReadS [BlockDeviceMapping]
readsPrec :: Int -> ReadS BlockDeviceMapping
$creadsPrec :: Int -> ReadS BlockDeviceMapping
Prelude.Read, Int -> BlockDeviceMapping -> ShowS
[BlockDeviceMapping] -> ShowS
BlockDeviceMapping -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlockDeviceMapping] -> ShowS
$cshowList :: [BlockDeviceMapping] -> ShowS
show :: BlockDeviceMapping -> String
$cshow :: BlockDeviceMapping -> String
showsPrec :: Int -> BlockDeviceMapping -> ShowS
$cshowsPrec :: Int -> BlockDeviceMapping -> ShowS
Prelude.Show, forall x. Rep BlockDeviceMapping x -> BlockDeviceMapping
forall x. BlockDeviceMapping -> Rep BlockDeviceMapping x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlockDeviceMapping x -> BlockDeviceMapping
$cfrom :: forall x. BlockDeviceMapping -> Rep BlockDeviceMapping x
Prelude.Generic)

-- |
-- Create a value of 'BlockDeviceMapping' 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:
--
-- 'deviceName', 'blockDeviceMapping_deviceName' - The device name that is exposed to the instance, such as @\/dev\/sdh@.
-- For the root device, you can use the explicit device name or you can set
-- this parameter to @ROOT_DEVICE@ and AWS OpsWorks Stacks will provide the
-- correct device name.
--
-- 'ebs', 'blockDeviceMapping_ebs' - An @EBSBlockDevice@ that defines how to configure an Amazon EBS volume
-- when the instance is launched.
--
-- 'noDevice', 'blockDeviceMapping_noDevice' - Suppresses the specified device included in the AMI\'s block device
-- mapping.
--
-- 'virtualName', 'blockDeviceMapping_virtualName' - The virtual device name. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html BlockDeviceMapping>.
newBlockDeviceMapping ::
  BlockDeviceMapping
newBlockDeviceMapping :: BlockDeviceMapping
newBlockDeviceMapping =
  BlockDeviceMapping'
    { $sel:deviceName:BlockDeviceMapping' :: Maybe Text
deviceName = forall a. Maybe a
Prelude.Nothing,
      $sel:ebs:BlockDeviceMapping' :: Maybe EbsBlockDevice
ebs = forall a. Maybe a
Prelude.Nothing,
      $sel:noDevice:BlockDeviceMapping' :: Maybe Text
noDevice = forall a. Maybe a
Prelude.Nothing,
      $sel:virtualName:BlockDeviceMapping' :: Maybe Text
virtualName = forall a. Maybe a
Prelude.Nothing
    }

-- | The device name that is exposed to the instance, such as @\/dev\/sdh@.
-- For the root device, you can use the explicit device name or you can set
-- this parameter to @ROOT_DEVICE@ and AWS OpsWorks Stacks will provide the
-- correct device name.
blockDeviceMapping_deviceName :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Prelude.Text)
blockDeviceMapping_deviceName :: Lens' BlockDeviceMapping (Maybe Text)
blockDeviceMapping_deviceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockDeviceMapping' {Maybe Text
deviceName :: Maybe Text
$sel:deviceName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
deviceName} -> Maybe Text
deviceName) (\s :: BlockDeviceMapping
s@BlockDeviceMapping' {} Maybe Text
a -> BlockDeviceMapping
s {$sel:deviceName:BlockDeviceMapping' :: Maybe Text
deviceName = Maybe Text
a} :: BlockDeviceMapping)

-- | An @EBSBlockDevice@ that defines how to configure an Amazon EBS volume
-- when the instance is launched.
blockDeviceMapping_ebs :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe EbsBlockDevice)
blockDeviceMapping_ebs :: Lens' BlockDeviceMapping (Maybe EbsBlockDevice)
blockDeviceMapping_ebs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockDeviceMapping' {Maybe EbsBlockDevice
ebs :: Maybe EbsBlockDevice
$sel:ebs:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe EbsBlockDevice
ebs} -> Maybe EbsBlockDevice
ebs) (\s :: BlockDeviceMapping
s@BlockDeviceMapping' {} Maybe EbsBlockDevice
a -> BlockDeviceMapping
s {$sel:ebs:BlockDeviceMapping' :: Maybe EbsBlockDevice
ebs = Maybe EbsBlockDevice
a} :: BlockDeviceMapping)

-- | Suppresses the specified device included in the AMI\'s block device
-- mapping.
blockDeviceMapping_noDevice :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Prelude.Text)
blockDeviceMapping_noDevice :: Lens' BlockDeviceMapping (Maybe Text)
blockDeviceMapping_noDevice = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockDeviceMapping' {Maybe Text
noDevice :: Maybe Text
$sel:noDevice:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
noDevice} -> Maybe Text
noDevice) (\s :: BlockDeviceMapping
s@BlockDeviceMapping' {} Maybe Text
a -> BlockDeviceMapping
s {$sel:noDevice:BlockDeviceMapping' :: Maybe Text
noDevice = Maybe Text
a} :: BlockDeviceMapping)

-- | The virtual device name. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html BlockDeviceMapping>.
blockDeviceMapping_virtualName :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Prelude.Text)
blockDeviceMapping_virtualName :: Lens' BlockDeviceMapping (Maybe Text)
blockDeviceMapping_virtualName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockDeviceMapping' {Maybe Text
virtualName :: Maybe Text
$sel:virtualName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
virtualName} -> Maybe Text
virtualName) (\s :: BlockDeviceMapping
s@BlockDeviceMapping' {} Maybe Text
a -> BlockDeviceMapping
s {$sel:virtualName:BlockDeviceMapping' :: Maybe Text
virtualName = Maybe Text
a} :: BlockDeviceMapping)

instance Data.FromJSON BlockDeviceMapping where
  parseJSON :: Value -> Parser BlockDeviceMapping
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"BlockDeviceMapping"
      ( \Object
x ->
          Maybe Text
-> Maybe EbsBlockDevice
-> Maybe Text
-> Maybe Text
-> BlockDeviceMapping
BlockDeviceMapping'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"DeviceName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Ebs")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"NoDevice")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"VirtualName")
      )

instance Prelude.Hashable BlockDeviceMapping where
  hashWithSalt :: Int -> BlockDeviceMapping -> Int
hashWithSalt Int
_salt BlockDeviceMapping' {Maybe Text
Maybe EbsBlockDevice
virtualName :: Maybe Text
noDevice :: Maybe Text
ebs :: Maybe EbsBlockDevice
deviceName :: Maybe Text
$sel:virtualName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
$sel:noDevice:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
$sel:ebs:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe EbsBlockDevice
$sel:deviceName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
deviceName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EbsBlockDevice
ebs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
noDevice
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
virtualName

instance Prelude.NFData BlockDeviceMapping where
  rnf :: BlockDeviceMapping -> ()
rnf BlockDeviceMapping' {Maybe Text
Maybe EbsBlockDevice
virtualName :: Maybe Text
noDevice :: Maybe Text
ebs :: Maybe EbsBlockDevice
deviceName :: Maybe Text
$sel:virtualName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
$sel:noDevice:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
$sel:ebs:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe EbsBlockDevice
$sel:deviceName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
deviceName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EbsBlockDevice
ebs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
noDevice
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
virtualName

instance Data.ToJSON BlockDeviceMapping where
  toJSON :: BlockDeviceMapping -> Value
toJSON BlockDeviceMapping' {Maybe Text
Maybe EbsBlockDevice
virtualName :: Maybe Text
noDevice :: Maybe Text
ebs :: Maybe EbsBlockDevice
deviceName :: Maybe Text
$sel:virtualName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
$sel:noDevice:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
$sel:ebs:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe EbsBlockDevice
$sel:deviceName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DeviceName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
deviceName,
            (Key
"Ebs" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EbsBlockDevice
ebs,
            (Key
"NoDevice" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
noDevice,
            (Key
"VirtualName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
virtualName
          ]
      )