{-# 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-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.EbsBlockDevice 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.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 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 snapshot ID.
    EbsBlockDevice -> Maybe Text
snapshotId :: Prelude.Maybe Prelude.Text,
    -- | 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 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
  }
  deriving (EbsBlockDevice -> EbsBlockDevice -> Bool
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]
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
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. 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.
--
-- '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>.
--
-- 'snapshotId', 'ebsBlockDevice_snapshotId' - The snapshot ID.
--
-- 'volumeSize', 'ebsBlockDevice_volumeSize' - The volume size, in GiB. 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).
newEbsBlockDevice ::
  EbsBlockDevice
newEbsBlockDevice :: EbsBlockDevice
newEbsBlockDevice =
  EbsBlockDevice'
    { $sel:deleteOnTermination:EbsBlockDevice' :: Maybe Bool
deleteOnTermination =
        forall a. Maybe a
Prelude.Nothing,
      $sel:iops:EbsBlockDevice' :: Maybe Int
iops = forall a. Maybe a
Prelude.Nothing,
      $sel:snapshotId:EbsBlockDevice' :: Maybe Text
snapshotId = forall a. Maybe a
Prelude.Nothing,
      $sel:volumeSize:EbsBlockDevice' :: Maybe Int
volumeSize = forall a. Maybe a
Prelude.Nothing,
      $sel:volumeType:EbsBlockDevice' :: Maybe VolumeType
volumeType = 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 :: Lens' EbsBlockDevice (Maybe Bool)
ebsBlockDevice_deleteOnTermination = 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 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 :: Lens' EbsBlockDevice (Maybe Int)
ebsBlockDevice_iops = 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 snapshot ID.
ebsBlockDevice_snapshotId :: Lens.Lens' EbsBlockDevice (Prelude.Maybe Prelude.Text)
ebsBlockDevice_snapshotId :: Lens' EbsBlockDevice (Maybe Text)
ebsBlockDevice_snapshotId = 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)

-- | 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 :: Lens' EbsBlockDevice (Maybe Int)
ebsBlockDevice_volumeSize = 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 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 :: Lens' EbsBlockDevice (Maybe VolumeType)
ebsBlockDevice_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)

instance Data.FromJSON EbsBlockDevice where
  parseJSON :: Value -> Parser EbsBlockDevice
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EbsBlockDevice"
      ( \Object
x ->
          Maybe Bool
-> Maybe Int
-> Maybe Text
-> Maybe Int
-> Maybe VolumeType
-> EbsBlockDevice
EbsBlockDevice'
            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
"DeleteOnTermination")
            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
"Iops")
            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
"SnapshotId")
            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
"VolumeSize")
            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
"VolumeType")
      )

instance Prelude.Hashable EbsBlockDevice where
  hashWithSalt :: Int -> EbsBlockDevice -> Int
hashWithSalt Int
_salt EbsBlockDevice' {Maybe Bool
Maybe Int
Maybe Text
Maybe VolumeType
volumeType :: Maybe VolumeType
volumeSize :: Maybe Int
snapshotId :: Maybe Text
iops :: Maybe Int
deleteOnTermination :: Maybe Bool
$sel:volumeType:EbsBlockDevice' :: EbsBlockDevice -> Maybe VolumeType
$sel:volumeSize:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
$sel:snapshotId:EbsBlockDevice' :: EbsBlockDevice -> Maybe Text
$sel:iops:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
$sel:deleteOnTermination:EbsBlockDevice' :: EbsBlockDevice -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
deleteOnTermination
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
iops
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
snapshotId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
volumeSize
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe VolumeType
volumeType

instance Prelude.NFData EbsBlockDevice where
  rnf :: EbsBlockDevice -> ()
rnf EbsBlockDevice' {Maybe Bool
Maybe Int
Maybe Text
Maybe VolumeType
volumeType :: Maybe VolumeType
volumeSize :: Maybe Int
snapshotId :: Maybe Text
iops :: Maybe Int
deleteOnTermination :: Maybe Bool
$sel:volumeType:EbsBlockDevice' :: EbsBlockDevice -> Maybe VolumeType
$sel:volumeSize:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
$sel:snapshotId:EbsBlockDevice' :: EbsBlockDevice -> Maybe Text
$sel:iops:EbsBlockDevice' :: EbsBlockDevice -> Maybe Int
$sel:deleteOnTermination:EbsBlockDevice' :: EbsBlockDevice -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
deleteOnTermination
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
iops
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
snapshotId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
volumeSize
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe VolumeType
volumeType

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