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

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

-- | Describes a block device mapping.
--
-- /See:/ 'newBlockDeviceMapping' smart constructor.
data BlockDeviceMapping = BlockDeviceMapping'
  { -- | The name of the virtual device (for example, @ephemeral0@).
    --
    -- You can specify either @VirtualName@ or @Ebs@, but not both.
    BlockDeviceMapping -> Maybe Text
virtualName :: Prelude.Maybe Prelude.Text,
    -- | Setting this value to @true@ suppresses the specified device included in
    -- the block device mapping of the AMI.
    --
    -- 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.
    --
    -- If you specify @NoDevice@, you cannot specify @Ebs@.
    BlockDeviceMapping -> Maybe Bool
noDevice :: Prelude.Maybe Prelude.Bool,
    -- | Parameters used to automatically set up EBS volumes when an instance is
    -- launched.
    --
    -- You can specify either @VirtualName@ or @Ebs@, but not both.
    BlockDeviceMapping -> Maybe Ebs
ebs :: Prelude.Maybe Ebs,
    -- | The device name exposed to the EC2 instance (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/.
    BlockDeviceMapping -> Text
deviceName :: Prelude.Text
  }
  deriving (BlockDeviceMapping -> BlockDeviceMapping -> Bool
(BlockDeviceMapping -> BlockDeviceMapping -> Bool)
-> (BlockDeviceMapping -> BlockDeviceMapping -> Bool)
-> Eq BlockDeviceMapping
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]
(Int -> ReadS BlockDeviceMapping)
-> ReadS [BlockDeviceMapping]
-> ReadPrec BlockDeviceMapping
-> ReadPrec [BlockDeviceMapping]
-> Read 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
(Int -> BlockDeviceMapping -> ShowS)
-> (BlockDeviceMapping -> String)
-> ([BlockDeviceMapping] -> ShowS)
-> Show BlockDeviceMapping
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. BlockDeviceMapping -> Rep BlockDeviceMapping x)
-> (forall x. Rep BlockDeviceMapping x -> BlockDeviceMapping)
-> Generic BlockDeviceMapping
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:
--
-- 'virtualName', 'blockDeviceMapping_virtualName' - The name of the virtual device (for example, @ephemeral0@).
--
-- You can specify either @VirtualName@ or @Ebs@, but not both.
--
-- 'noDevice', 'blockDeviceMapping_noDevice' - Setting this value to @true@ suppresses the specified device included in
-- the block device mapping of the AMI.
--
-- 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.
--
-- If you specify @NoDevice@, you cannot specify @Ebs@.
--
-- 'ebs', 'blockDeviceMapping_ebs' - Parameters used to automatically set up EBS volumes when an instance is
-- launched.
--
-- You can specify either @VirtualName@ or @Ebs@, but not both.
--
-- 'deviceName', 'blockDeviceMapping_deviceName' - The device name exposed to the EC2 instance (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/.
newBlockDeviceMapping ::
  -- | 'deviceName'
  Prelude.Text ->
  BlockDeviceMapping
newBlockDeviceMapping :: Text -> BlockDeviceMapping
newBlockDeviceMapping Text
pDeviceName_ =
  BlockDeviceMapping' :: Maybe Text -> Maybe Bool -> Maybe Ebs -> Text -> BlockDeviceMapping
BlockDeviceMapping'
    { $sel:virtualName:BlockDeviceMapping' :: Maybe Text
virtualName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:noDevice:BlockDeviceMapping' :: Maybe Bool
noDevice = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:ebs:BlockDeviceMapping' :: Maybe Ebs
ebs = Maybe Ebs
forall a. Maybe a
Prelude.Nothing,
      $sel:deviceName:BlockDeviceMapping' :: Text
deviceName = Text
pDeviceName_
    }

-- | The name of the virtual device (for example, @ephemeral0@).
--
-- You can specify either @VirtualName@ or @Ebs@, but not both.
blockDeviceMapping_virtualName :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Prelude.Text)
blockDeviceMapping_virtualName :: (Maybe Text -> f (Maybe Text))
-> BlockDeviceMapping -> f BlockDeviceMapping
blockDeviceMapping_virtualName = (BlockDeviceMapping -> Maybe Text)
-> (BlockDeviceMapping -> Maybe Text -> BlockDeviceMapping)
-> Lens
     BlockDeviceMapping BlockDeviceMapping (Maybe Text) (Maybe Text)
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)

-- | Setting this value to @true@ suppresses the specified device included in
-- the block device mapping of the AMI.
--
-- 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.
--
-- If you specify @NoDevice@, you cannot specify @Ebs@.
blockDeviceMapping_noDevice :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Prelude.Bool)
blockDeviceMapping_noDevice :: (Maybe Bool -> f (Maybe Bool))
-> BlockDeviceMapping -> f BlockDeviceMapping
blockDeviceMapping_noDevice = (BlockDeviceMapping -> Maybe Bool)
-> (BlockDeviceMapping -> Maybe Bool -> BlockDeviceMapping)
-> Lens
     BlockDeviceMapping BlockDeviceMapping (Maybe Bool) (Maybe Bool)
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)

-- | Parameters used to automatically set up EBS volumes when an instance is
-- launched.
--
-- You can specify either @VirtualName@ or @Ebs@, but not both.
blockDeviceMapping_ebs :: Lens.Lens' BlockDeviceMapping (Prelude.Maybe Ebs)
blockDeviceMapping_ebs :: (Maybe Ebs -> f (Maybe Ebs))
-> BlockDeviceMapping -> f BlockDeviceMapping
blockDeviceMapping_ebs = (BlockDeviceMapping -> Maybe Ebs)
-> (BlockDeviceMapping -> Maybe Ebs -> BlockDeviceMapping)
-> Lens
     BlockDeviceMapping BlockDeviceMapping (Maybe Ebs) (Maybe 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)

-- | The device name exposed to the EC2 instance (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/.
blockDeviceMapping_deviceName :: Lens.Lens' BlockDeviceMapping Prelude.Text
blockDeviceMapping_deviceName :: (Text -> f Text) -> BlockDeviceMapping -> f BlockDeviceMapping
blockDeviceMapping_deviceName = (BlockDeviceMapping -> Text)
-> (BlockDeviceMapping -> Text -> BlockDeviceMapping)
-> Lens BlockDeviceMapping BlockDeviceMapping Text Text
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 Core.FromXML BlockDeviceMapping where
  parseXML :: [Node] -> Either String BlockDeviceMapping
parseXML [Node]
x =
    Maybe Text -> Maybe Bool -> Maybe Ebs -> Text -> BlockDeviceMapping
BlockDeviceMapping'
      (Maybe Text
 -> Maybe Bool -> Maybe Ebs -> Text -> BlockDeviceMapping)
-> Either String (Maybe Text)
-> Either
     String (Maybe Bool -> Maybe Ebs -> Text -> BlockDeviceMapping)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"VirtualName")
      Either
  String (Maybe Bool -> Maybe Ebs -> Text -> BlockDeviceMapping)
-> Either String (Maybe Bool)
-> Either String (Maybe Ebs -> Text -> BlockDeviceMapping)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"NoDevice")
      Either String (Maybe Ebs -> Text -> BlockDeviceMapping)
-> Either String (Maybe Ebs)
-> Either String (Text -> BlockDeviceMapping)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Ebs)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Ebs")
      Either String (Text -> BlockDeviceMapping)
-> Either String Text -> Either String BlockDeviceMapping
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"DeviceName")

instance Prelude.Hashable BlockDeviceMapping

instance Prelude.NFData BlockDeviceMapping

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