{-# 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.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.AutoScaling.Types.BlockDeviceMapping where

import Amazonka.AutoScaling.Types.Ebs
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Describes a block device mapping.
--
-- /See:/ 'newBlockDeviceMapping' smart constructor.
data BlockDeviceMapping = BlockDeviceMapping'
  { -- | Information to attach an EBS volume to an instance at launch.
    BlockDeviceMapping -> Maybe Ebs
ebs :: Prelude.Maybe Ebs,
    -- | Setting this value to @true@ prevents a volume that is included in the
    -- block device mapping of the AMI from being mapped to the specified
    -- device name at launch.
    --
    -- If @NoDevice@ is @true@ for the root device, instances might fail the
    -- EC2 health check. In that case, Amazon EC2 Auto Scaling launches
    -- replacement instances.
    BlockDeviceMapping -> Maybe Bool
noDevice :: Prelude.Maybe Prelude.Bool,
    -- | The name of the instance store volume (virtual device) to attach to an
    -- instance at launch. The name must be in the form ephemeral/X/ where /X/
    -- is a number starting from zero (0), for example, @ephemeral0@.
    BlockDeviceMapping -> Maybe Text
virtualName :: Prelude.Maybe Prelude.Text,
    -- | The device name assigned to the volume (for example, @\/dev\/sdh@ or
    -- @xvdh@). For more information, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html Device naming on Linux instances>
    -- in the /Amazon EC2 User Guide for Linux Instances/.
    --
    -- To define a block device mapping, set the device name and exactly one of
    -- the following properties: @Ebs@, @NoDevice@, or @VirtualName@.
    BlockDeviceMapping -> Text
deviceName :: 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:
--
-- 'ebs', 'blockDeviceMapping_ebs' - Information to attach an EBS volume to an instance at launch.
--
-- 'noDevice', 'blockDeviceMapping_noDevice' - Setting this value to @true@ prevents a volume that is included in the
-- block device mapping of the AMI from being mapped to the specified
-- device name at launch.
--
-- If @NoDevice@ is @true@ for the root device, instances might fail the
-- EC2 health check. In that case, Amazon EC2 Auto Scaling launches
-- replacement instances.
--
-- 'virtualName', 'blockDeviceMapping_virtualName' - The name of the instance store volume (virtual device) to attach to an
-- instance at launch. The name must be in the form ephemeral/X/ where /X/
-- is a number starting from zero (0), for example, @ephemeral0@.
--
-- 'deviceName', 'blockDeviceMapping_deviceName' - The device name assigned to the volume (for example, @\/dev\/sdh@ or
-- @xvdh@). For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html Device naming on Linux instances>
-- in the /Amazon EC2 User Guide for Linux Instances/.
--
-- To define a block device mapping, set the device name and exactly one of
-- the following properties: @Ebs@, @NoDevice@, or @VirtualName@.
newBlockDeviceMapping ::
  -- | 'deviceName'
  Prelude.Text ->
  BlockDeviceMapping
newBlockDeviceMapping :: Text -> BlockDeviceMapping
newBlockDeviceMapping Text
pDeviceName_ =
  BlockDeviceMapping'
    { $sel:ebs:BlockDeviceMapping' :: Maybe Ebs
ebs = forall a. Maybe a
Prelude.Nothing,
      $sel:noDevice:BlockDeviceMapping' :: Maybe Bool
noDevice = forall a. Maybe a
Prelude.Nothing,
      $sel:virtualName:BlockDeviceMapping' :: Maybe Text
virtualName = forall a. Maybe a
Prelude.Nothing,
      $sel:deviceName:BlockDeviceMapping' :: Text
deviceName = Text
pDeviceName_
    }

-- | Information to attach an EBS volume to an instance at launch.
blockDeviceMapping_ebs :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Ebs)
blockDeviceMapping_ebs :: Lens' BlockDeviceMapping (Maybe Ebs)
blockDeviceMapping_ebs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockDeviceMapping' {Maybe Ebs
ebs :: Maybe Ebs
$sel:ebs:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Ebs
ebs} -> Maybe Ebs
ebs) (\s :: BlockDeviceMapping
s@BlockDeviceMapping' {} Maybe Ebs
a -> BlockDeviceMapping
s {$sel:ebs:BlockDeviceMapping' :: Maybe Ebs
ebs = Maybe Ebs
a} :: BlockDeviceMapping)

-- | Setting this value to @true@ prevents a volume that is included in the
-- block device mapping of the AMI from being mapped to the specified
-- device name at launch.
--
-- If @NoDevice@ is @true@ for the root device, instances might fail the
-- EC2 health check. In that case, Amazon EC2 Auto Scaling launches
-- replacement instances.
blockDeviceMapping_noDevice :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Prelude.Bool)
blockDeviceMapping_noDevice :: Lens' BlockDeviceMapping (Maybe Bool)
blockDeviceMapping_noDevice = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockDeviceMapping' {Maybe Bool
noDevice :: Maybe Bool
$sel:noDevice:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Bool
noDevice} -> Maybe Bool
noDevice) (\s :: BlockDeviceMapping
s@BlockDeviceMapping' {} Maybe Bool
a -> BlockDeviceMapping
s {$sel:noDevice:BlockDeviceMapping' :: Maybe Bool
noDevice = Maybe Bool
a} :: BlockDeviceMapping)

-- | The name of the instance store volume (virtual device) to attach to an
-- instance at launch. The name must be in the form ephemeral/X/ where /X/
-- is a number starting from zero (0), for example, @ephemeral0@.
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)

-- | The device name assigned to the volume (for example, @\/dev\/sdh@ or
-- @xvdh@). For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html Device naming on Linux instances>
-- in the /Amazon EC2 User Guide for Linux Instances/.
--
-- To define a block device mapping, set the device name and exactly one of
-- the following properties: @Ebs@, @NoDevice@, or @VirtualName@.
blockDeviceMapping_deviceName :: Lens.Lens' BlockDeviceMapping Prelude.Text
blockDeviceMapping_deviceName :: Lens' BlockDeviceMapping Text
blockDeviceMapping_deviceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockDeviceMapping' {Text
deviceName :: Text
$sel:deviceName:BlockDeviceMapping' :: BlockDeviceMapping -> Text
deviceName} -> Text
deviceName) (\s :: BlockDeviceMapping
s@BlockDeviceMapping' {} Text
a -> BlockDeviceMapping
s {$sel:deviceName:BlockDeviceMapping' :: Text
deviceName = Text
a} :: BlockDeviceMapping)

instance Data.FromXML BlockDeviceMapping where
  parseXML :: [Node] -> Either String BlockDeviceMapping
parseXML [Node]
x =
    Maybe Ebs -> Maybe Bool -> Maybe Text -> Text -> BlockDeviceMapping
BlockDeviceMapping'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Ebs")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"NoDevice")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"VirtualName")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"DeviceName")

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

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

instance Data.ToQuery BlockDeviceMapping where
  toQuery :: BlockDeviceMapping -> QueryString
toQuery BlockDeviceMapping' {Maybe Bool
Maybe Text
Maybe Ebs
Text
deviceName :: Text
virtualName :: Maybe Text
noDevice :: Maybe Bool
ebs :: Maybe Ebs
$sel:deviceName:BlockDeviceMapping' :: BlockDeviceMapping -> Text
$sel:virtualName:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Text
$sel:noDevice:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Bool
$sel:ebs:BlockDeviceMapping' :: BlockDeviceMapping -> Maybe Ebs
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Ebs" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Ebs
ebs,
        ByteString
"NoDevice" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
noDevice,
        ByteString
"VirtualName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
virtualName,
        ByteString
"DeviceName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
deviceName
      ]