{-# 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.EbsBlockDevice
-- 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.OpsWorks.Types.EbsBlockDevice where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.OpsWorks.Types.VolumeType
import qualified Amazonka.Prelude as Prelude

-- | Describes an Amazon EBS volume. This data type maps directly to the
-- Amazon EC2
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html EbsBlockDevice>
-- data type.
--
-- /See:/ 'newEbsBlockDevice' smart constructor.
data EbsBlockDevice = EbsBlockDevice'
  { -- | Whether the volume is deleted on instance termination.
    EbsBlockDevice -> Maybe Bool
deleteOnTermination :: Prelude.Maybe Prelude.Bool,
    -- | The volume size, in GiB. For more information, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html EbsBlockDevice>.
    EbsBlockDevice -> Maybe Int
volumeSize :: Prelude.Maybe Prelude.Int,
    -- | The number of I\/O operations per second (IOPS) that the volume
    -- supports. For more information, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html EbsBlockDevice>.
    EbsBlockDevice -> Maybe Int
iops :: Prelude.Maybe Prelude.Int,
    -- | The volume type. @gp2@ for General Purpose (SSD) volumes, @io1@ for
    -- Provisioned IOPS (SSD) volumes, @st1@ for Throughput Optimized hard disk
    -- drives (HDD), @sc1@ for Cold HDD,and @standard@ for Magnetic volumes.
    --
    -- If you specify the @io1@ volume type, you must also specify a value for
    -- the @Iops@ attribute. The maximum ratio of provisioned IOPS to requested
    -- volume size (in GiB) is 50:1. AWS uses the default volume size (in GiB)
    -- specified in the AMI attributes to set IOPS to 50 x (volume size).
    EbsBlockDevice -> Maybe VolumeType
volumeType :: Prelude.Maybe VolumeType,
    -- | The snapshot ID.
    EbsBlockDevice -> Maybe Text
snapshotId :: Prelude.Maybe Prelude.Text
  }
  deriving (EbsBlockDevice -> EbsBlockDevice -> Bool
(EbsBlockDevice -> EbsBlockDevice -> Bool)
-> (EbsBlockDevice -> EbsBlockDevice -> Bool) -> Eq EbsBlockDevice
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EbsBlockDevice -> EbsBlockDevice -> Bool
$c/= :: EbsBlockDevice -> EbsBlockDevice -> Bool
== :: EbsBlockDevice -> EbsBlockDevice -> Bool
$c== :: EbsBlockDevice -> EbsBlockDevice -> Bool
Prelude.Eq, ReadPrec [EbsBlockDevice]
ReadPrec EbsBlockDevice
Int -> ReadS EbsBlockDevice
ReadS [EbsBlockDevice]
(Int -> ReadS EbsBlockDevice)
-> ReadS [EbsBlockDevice]
-> ReadPrec EbsBlockDevice
-> ReadPrec [EbsBlockDevice]
-> Read EbsBlockDevice
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EbsBlockDevice]
$creadListPrec :: ReadPrec [EbsBlockDevice]
readPrec :: ReadPrec EbsBlockDevice
$creadPrec :: ReadPrec EbsBlockDevice
readList :: ReadS [EbsBlockDevice]
$creadList :: ReadS [EbsBlockDevice]
readsPrec :: Int -> ReadS EbsBlockDevice
$creadsPrec :: Int -> ReadS EbsBlockDevice
Prelude.Read, Int -> EbsBlockDevice -> ShowS
[EbsBlockDevice] -> ShowS
EbsBlockDevice -> String
(Int -> EbsBlockDevice -> ShowS)
-> (EbsBlockDevice -> String)
-> ([EbsBlockDevice] -> ShowS)
-> Show EbsBlockDevice
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EbsBlockDevice] -> ShowS
$cshowList :: [EbsBlockDevice] -> ShowS
show :: EbsBlockDevice -> String
$cshow :: EbsBlockDevice -> String
showsPrec :: Int -> EbsBlockDevice -> ShowS
$cshowsPrec :: Int -> EbsBlockDevice -> ShowS
Prelude.Show, (forall x. EbsBlockDevice -> Rep EbsBlockDevice x)
-> (forall x. Rep EbsBlockDevice x -> EbsBlockDevice)
-> Generic EbsBlockDevice
forall x. Rep EbsBlockDevice x -> EbsBlockDevice
forall x. EbsBlockDevice -> Rep EbsBlockDevice x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EbsBlockDevice x -> EbsBlockDevice
$cfrom :: forall x. EbsBlockDevice -> Rep EbsBlockDevice x
Prelude.Generic)

-- |
-- Create a value of 'EbsBlockDevice' 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:
--
-- 'deleteOnTermination', 'ebsBlockDevice_deleteOnTermination' - Whether the volume is deleted on instance termination.
--
-- 'volumeSize', 'ebsBlockDevice_volumeSize' - The volume size, in GiB. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html EbsBlockDevice>.
--
-- 'iops', 'ebsBlockDevice_iops' - The number of I\/O operations per second (IOPS) that the volume
-- supports. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html EbsBlockDevice>.
--
-- 'volumeType', 'ebsBlockDevice_volumeType' - The volume type. @gp2@ for General Purpose (SSD) volumes, @io1@ for
-- Provisioned IOPS (SSD) volumes, @st1@ for Throughput Optimized hard disk
-- drives (HDD), @sc1@ for Cold HDD,and @standard@ for Magnetic volumes.
--
-- If you specify the @io1@ volume type, you must also specify a value for
-- the @Iops@ attribute. The maximum ratio of provisioned IOPS to requested
-- volume size (in GiB) is 50:1. AWS uses the default volume size (in GiB)
-- specified in the AMI attributes to set IOPS to 50 x (volume size).
--
-- 'snapshotId', 'ebsBlockDevice_snapshotId' - The snapshot ID.
newEbsBlockDevice ::
  EbsBlockDevice
newEbsBlockDevice :: EbsBlockDevice
newEbsBlockDevice =
  EbsBlockDevice' :: Maybe Bool
-> Maybe Int
-> Maybe Int
-> Maybe VolumeType
-> Maybe Text
-> EbsBlockDevice
EbsBlockDevice'
    { $sel:deleteOnTermination:EbsBlockDevice' :: Maybe Bool
deleteOnTermination =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:volumeSize:EbsBlockDevice' :: Maybe Int
volumeSize = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:iops:EbsBlockDevice' :: Maybe Int
iops = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:volumeType:EbsBlockDevice' :: Maybe VolumeType
volumeType = Maybe VolumeType
forall a. Maybe a
Prelude.Nothing,
      $sel:snapshotId:EbsBlockDevice' :: Maybe Text
snapshotId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Whether the volume is deleted on instance termination.
ebsBlockDevice_deleteOnTermination :: Lens.Lens' EbsBlockDevice (Prelude.Maybe Prelude.Bool)
ebsBlockDevice_deleteOnTermination :: (Maybe Bool -> f (Maybe Bool))
-> EbsBlockDevice -> f EbsBlockDevice
ebsBlockDevice_deleteOnTermination = (EbsBlockDevice -> Maybe Bool)
-> (EbsBlockDevice -> Maybe Bool -> EbsBlockDevice)
-> Lens EbsBlockDevice EbsBlockDevice (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsBlockDevice' {Maybe Bool
deleteOnTermination :: Maybe Bool
$sel:deleteOnTermination:EbsBlockDevice' :: EbsBlockDevice -> Maybe Bool
deleteOnTermination} -> Maybe Bool
deleteOnTermination) (\s :: EbsBlockDevice
s@EbsBlockDevice' {} Maybe Bool
a -> EbsBlockDevice
s {$sel:deleteOnTermination:EbsBlockDevice' :: Maybe Bool
deleteOnTermination = Maybe Bool
a} :: EbsBlockDevice)

-- | The volume size, in GiB. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html EbsBlockDevice>.
ebsBlockDevice_volumeSize :: Lens.Lens' EbsBlockDevice (Prelude.Maybe Prelude.Int)
ebsBlockDevice_volumeSize :: (Maybe Int -> f (Maybe Int)) -> EbsBlockDevice -> f EbsBlockDevice
ebsBlockDevice_volumeSize = (EbsBlockDevice -> Maybe Int)
-> (EbsBlockDevice -> Maybe Int -> EbsBlockDevice)
-> Lens EbsBlockDevice EbsBlockDevice (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsBlockDevice' {Maybe Int
volumeSize :: Maybe Int
$sel:volumeSize:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
volumeSize} -> Maybe Int
volumeSize) (\s :: EbsBlockDevice
s@EbsBlockDevice' {} Maybe Int
a -> EbsBlockDevice
s {$sel:volumeSize:EbsBlockDevice' :: Maybe Int
volumeSize = Maybe Int
a} :: EbsBlockDevice)

-- | The number of I\/O operations per second (IOPS) that the volume
-- supports. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html EbsBlockDevice>.
ebsBlockDevice_iops :: Lens.Lens' EbsBlockDevice (Prelude.Maybe Prelude.Int)
ebsBlockDevice_iops :: (Maybe Int -> f (Maybe Int)) -> EbsBlockDevice -> f EbsBlockDevice
ebsBlockDevice_iops = (EbsBlockDevice -> Maybe Int)
-> (EbsBlockDevice -> Maybe Int -> EbsBlockDevice)
-> Lens EbsBlockDevice EbsBlockDevice (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsBlockDevice' {Maybe Int
iops :: Maybe Int
$sel:iops:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
iops} -> Maybe Int
iops) (\s :: EbsBlockDevice
s@EbsBlockDevice' {} Maybe Int
a -> EbsBlockDevice
s {$sel:iops:EbsBlockDevice' :: Maybe Int
iops = Maybe Int
a} :: EbsBlockDevice)

-- | The volume type. @gp2@ for General Purpose (SSD) volumes, @io1@ for
-- Provisioned IOPS (SSD) volumes, @st1@ for Throughput Optimized hard disk
-- drives (HDD), @sc1@ for Cold HDD,and @standard@ for Magnetic volumes.
--
-- If you specify the @io1@ volume type, you must also specify a value for
-- the @Iops@ attribute. The maximum ratio of provisioned IOPS to requested
-- volume size (in GiB) is 50:1. AWS uses the default volume size (in GiB)
-- specified in the AMI attributes to set IOPS to 50 x (volume size).
ebsBlockDevice_volumeType :: Lens.Lens' EbsBlockDevice (Prelude.Maybe VolumeType)
ebsBlockDevice_volumeType :: (Maybe VolumeType -> f (Maybe VolumeType))
-> EbsBlockDevice -> f EbsBlockDevice
ebsBlockDevice_volumeType = (EbsBlockDevice -> Maybe VolumeType)
-> (EbsBlockDevice -> Maybe VolumeType -> EbsBlockDevice)
-> Lens
     EbsBlockDevice EbsBlockDevice (Maybe VolumeType) (Maybe VolumeType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsBlockDevice' {Maybe VolumeType
volumeType :: Maybe VolumeType
$sel:volumeType:EbsBlockDevice' :: EbsBlockDevice -> Maybe VolumeType
volumeType} -> Maybe VolumeType
volumeType) (\s :: EbsBlockDevice
s@EbsBlockDevice' {} Maybe VolumeType
a -> EbsBlockDevice
s {$sel:volumeType:EbsBlockDevice' :: Maybe VolumeType
volumeType = Maybe VolumeType
a} :: EbsBlockDevice)

-- | The snapshot ID.
ebsBlockDevice_snapshotId :: Lens.Lens' EbsBlockDevice (Prelude.Maybe Prelude.Text)
ebsBlockDevice_snapshotId :: (Maybe Text -> f (Maybe Text))
-> EbsBlockDevice -> f EbsBlockDevice
ebsBlockDevice_snapshotId = (EbsBlockDevice -> Maybe Text)
-> (EbsBlockDevice -> Maybe Text -> EbsBlockDevice)
-> Lens EbsBlockDevice EbsBlockDevice (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsBlockDevice' {Maybe Text
snapshotId :: Maybe Text
$sel:snapshotId:EbsBlockDevice' :: EbsBlockDevice -> Maybe Text
snapshotId} -> Maybe Text
snapshotId) (\s :: EbsBlockDevice
s@EbsBlockDevice' {} Maybe Text
a -> EbsBlockDevice
s {$sel:snapshotId:EbsBlockDevice' :: Maybe Text
snapshotId = Maybe Text
a} :: EbsBlockDevice)

instance Core.FromJSON EbsBlockDevice where
  parseJSON :: Value -> Parser EbsBlockDevice
parseJSON =
    String
-> (Object -> Parser EbsBlockDevice)
-> Value
-> Parser EbsBlockDevice
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EbsBlockDevice"
      ( \Object
x ->
          Maybe Bool
-> Maybe Int
-> Maybe Int
-> Maybe VolumeType
-> Maybe Text
-> EbsBlockDevice
EbsBlockDevice'
            (Maybe Bool
 -> Maybe Int
 -> Maybe Int
 -> Maybe VolumeType
 -> Maybe Text
 -> EbsBlockDevice)
-> Parser (Maybe Bool)
-> Parser
     (Maybe Int
      -> Maybe Int -> Maybe VolumeType -> Maybe Text -> EbsBlockDevice)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DeleteOnTermination")
            Parser
  (Maybe Int
   -> Maybe Int -> Maybe VolumeType -> Maybe Text -> EbsBlockDevice)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int -> Maybe VolumeType -> Maybe Text -> EbsBlockDevice)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"VolumeSize")
            Parser
  (Maybe Int -> Maybe VolumeType -> Maybe Text -> EbsBlockDevice)
-> Parser (Maybe Int)
-> Parser (Maybe VolumeType -> Maybe Text -> EbsBlockDevice)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Iops")
            Parser (Maybe VolumeType -> Maybe Text -> EbsBlockDevice)
-> Parser (Maybe VolumeType)
-> Parser (Maybe Text -> EbsBlockDevice)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe VolumeType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"VolumeType")
            Parser (Maybe Text -> EbsBlockDevice)
-> Parser (Maybe Text) -> Parser EbsBlockDevice
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
"SnapshotId")
      )

instance Prelude.Hashable EbsBlockDevice

instance Prelude.NFData EbsBlockDevice

instance Core.ToJSON EbsBlockDevice where
  toJSON :: EbsBlockDevice -> Value
toJSON EbsBlockDevice' {Maybe Bool
Maybe Int
Maybe Text
Maybe VolumeType
snapshotId :: Maybe Text
volumeType :: Maybe VolumeType
iops :: Maybe Int
volumeSize :: Maybe Int
deleteOnTermination :: Maybe Bool
$sel:snapshotId:EbsBlockDevice' :: EbsBlockDevice -> Maybe Text
$sel:volumeType:EbsBlockDevice' :: EbsBlockDevice -> Maybe VolumeType
$sel:iops:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
$sel:volumeSize:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
$sel:deleteOnTermination:EbsBlockDevice' :: EbsBlockDevice -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DeleteOnTermination" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
deleteOnTermination,
            (Text
"VolumeSize" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
volumeSize,
            (Text
"Iops" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
iops,
            (Text
"VolumeType" Text -> VolumeType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (VolumeType -> Pair) -> Maybe VolumeType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe VolumeType
volumeType,
            (Text
"SnapshotId" 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
snapshotId
          ]
      )