{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.EC2.EnableEbsEncryptionByDefault
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Enables EBS encryption by default for your account in the current
-- Region.
--
-- After you enable encryption by default, the EBS volumes that you create
-- are always encrypted, either using the default KMS key or the KMS key
-- that you specified when you created each volume. For more information,
-- see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html Amazon EBS encryption>
-- in the /Amazon Elastic Compute Cloud User Guide/.
--
-- You can specify the default KMS key for encryption by default using
-- ModifyEbsDefaultKmsKeyId or ResetEbsDefaultKmsKeyId.
--
-- Enabling encryption by default has no effect on the encryption status of
-- your existing volumes.
--
-- After you enable encryption by default, you can no longer launch
-- instances using instance types that do not support encryption. For more
-- information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html#EBSEncryption_supported_instances Supported instance types>.
module Amazonka.EC2.EnableEbsEncryptionByDefault
  ( -- * Creating a Request
    EnableEbsEncryptionByDefault (..),
    newEnableEbsEncryptionByDefault,

    -- * Request Lenses
    enableEbsEncryptionByDefault_dryRun,

    -- * Destructuring the Response
    EnableEbsEncryptionByDefaultResponse (..),
    newEnableEbsEncryptionByDefaultResponse,

    -- * Response Lenses
    enableEbsEncryptionByDefaultResponse_ebsEncryptionByDefault,
    enableEbsEncryptionByDefaultResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EC2.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newEnableEbsEncryptionByDefault' smart constructor.
data EnableEbsEncryptionByDefault = EnableEbsEncryptionByDefault'
  { -- | Checks whether you have the required permissions for the action, without
    -- actually making the request, and provides an error response. If you have
    -- the required permissions, the error response is @DryRunOperation@.
    -- Otherwise, it is @UnauthorizedOperation@.
    EnableEbsEncryptionByDefault -> Maybe Bool
dryRun :: Prelude.Maybe Prelude.Bool
  }
  deriving (EnableEbsEncryptionByDefault
-> EnableEbsEncryptionByDefault -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableEbsEncryptionByDefault
-> EnableEbsEncryptionByDefault -> Bool
$c/= :: EnableEbsEncryptionByDefault
-> EnableEbsEncryptionByDefault -> Bool
== :: EnableEbsEncryptionByDefault
-> EnableEbsEncryptionByDefault -> Bool
$c== :: EnableEbsEncryptionByDefault
-> EnableEbsEncryptionByDefault -> Bool
Prelude.Eq, ReadPrec [EnableEbsEncryptionByDefault]
ReadPrec EnableEbsEncryptionByDefault
Int -> ReadS EnableEbsEncryptionByDefault
ReadS [EnableEbsEncryptionByDefault]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableEbsEncryptionByDefault]
$creadListPrec :: ReadPrec [EnableEbsEncryptionByDefault]
readPrec :: ReadPrec EnableEbsEncryptionByDefault
$creadPrec :: ReadPrec EnableEbsEncryptionByDefault
readList :: ReadS [EnableEbsEncryptionByDefault]
$creadList :: ReadS [EnableEbsEncryptionByDefault]
readsPrec :: Int -> ReadS EnableEbsEncryptionByDefault
$creadsPrec :: Int -> ReadS EnableEbsEncryptionByDefault
Prelude.Read, Int -> EnableEbsEncryptionByDefault -> ShowS
[EnableEbsEncryptionByDefault] -> ShowS
EnableEbsEncryptionByDefault -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableEbsEncryptionByDefault] -> ShowS
$cshowList :: [EnableEbsEncryptionByDefault] -> ShowS
show :: EnableEbsEncryptionByDefault -> String
$cshow :: EnableEbsEncryptionByDefault -> String
showsPrec :: Int -> EnableEbsEncryptionByDefault -> ShowS
$cshowsPrec :: Int -> EnableEbsEncryptionByDefault -> ShowS
Prelude.Show, forall x.
Rep EnableEbsEncryptionByDefault x -> EnableEbsEncryptionByDefault
forall x.
EnableEbsEncryptionByDefault -> Rep EnableEbsEncryptionByDefault x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EnableEbsEncryptionByDefault x -> EnableEbsEncryptionByDefault
$cfrom :: forall x.
EnableEbsEncryptionByDefault -> Rep EnableEbsEncryptionByDefault x
Prelude.Generic)

-- |
-- Create a value of 'EnableEbsEncryptionByDefault' 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:
--
-- 'dryRun', 'enableEbsEncryptionByDefault_dryRun' - Checks whether you have the required permissions for the action, without
-- actually making the request, and provides an error response. If you have
-- the required permissions, the error response is @DryRunOperation@.
-- Otherwise, it is @UnauthorizedOperation@.
newEnableEbsEncryptionByDefault ::
  EnableEbsEncryptionByDefault
newEnableEbsEncryptionByDefault :: EnableEbsEncryptionByDefault
newEnableEbsEncryptionByDefault =
  EnableEbsEncryptionByDefault'
    { $sel:dryRun:EnableEbsEncryptionByDefault' :: Maybe Bool
dryRun =
        forall a. Maybe a
Prelude.Nothing
    }

-- | Checks whether you have the required permissions for the action, without
-- actually making the request, and provides an error response. If you have
-- the required permissions, the error response is @DryRunOperation@.
-- Otherwise, it is @UnauthorizedOperation@.
enableEbsEncryptionByDefault_dryRun :: Lens.Lens' EnableEbsEncryptionByDefault (Prelude.Maybe Prelude.Bool)
enableEbsEncryptionByDefault_dryRun :: Lens' EnableEbsEncryptionByDefault (Maybe Bool)
enableEbsEncryptionByDefault_dryRun = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableEbsEncryptionByDefault' {Maybe Bool
dryRun :: Maybe Bool
$sel:dryRun:EnableEbsEncryptionByDefault' :: EnableEbsEncryptionByDefault -> Maybe Bool
dryRun} -> Maybe Bool
dryRun) (\s :: EnableEbsEncryptionByDefault
s@EnableEbsEncryptionByDefault' {} Maybe Bool
a -> EnableEbsEncryptionByDefault
s {$sel:dryRun:EnableEbsEncryptionByDefault' :: Maybe Bool
dryRun = Maybe Bool
a} :: EnableEbsEncryptionByDefault)

instance Core.AWSRequest EnableEbsEncryptionByDefault where
  type
    AWSResponse EnableEbsEncryptionByDefault =
      EnableEbsEncryptionByDefaultResponse
  request :: (Service -> Service)
-> EnableEbsEncryptionByDefault
-> Request EnableEbsEncryptionByDefault
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy EnableEbsEncryptionByDefault
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EnableEbsEncryptionByDefault)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Bool -> Int -> EnableEbsEncryptionByDefaultResponse
EnableEbsEncryptionByDefaultResponse'
            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
"ebsEncryptionByDefault")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance
  Prelude.Hashable
    EnableEbsEncryptionByDefault
  where
  hashWithSalt :: Int -> EnableEbsEncryptionByDefault -> Int
hashWithSalt Int
_salt EnableEbsEncryptionByDefault' {Maybe Bool
dryRun :: Maybe Bool
$sel:dryRun:EnableEbsEncryptionByDefault' :: EnableEbsEncryptionByDefault -> Maybe Bool
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
dryRun

instance Prelude.NFData EnableEbsEncryptionByDefault where
  rnf :: EnableEbsEncryptionByDefault -> ()
rnf EnableEbsEncryptionByDefault' {Maybe Bool
dryRun :: Maybe Bool
$sel:dryRun:EnableEbsEncryptionByDefault' :: EnableEbsEncryptionByDefault -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
dryRun

instance Data.ToHeaders EnableEbsEncryptionByDefault where
  toHeaders :: EnableEbsEncryptionByDefault -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath EnableEbsEncryptionByDefault where
  toPath :: EnableEbsEncryptionByDefault -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery EnableEbsEncryptionByDefault where
  toQuery :: EnableEbsEncryptionByDefault -> QueryString
toQuery EnableEbsEncryptionByDefault' {Maybe Bool
dryRun :: Maybe Bool
$sel:dryRun:EnableEbsEncryptionByDefault' :: EnableEbsEncryptionByDefault -> Maybe Bool
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: ( ByteString
"EnableEbsEncryptionByDefault" ::
                      Prelude.ByteString
                  ),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2016-11-15" :: Prelude.ByteString),
        ByteString
"DryRun" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
dryRun
      ]

-- | /See:/ 'newEnableEbsEncryptionByDefaultResponse' smart constructor.
data EnableEbsEncryptionByDefaultResponse = EnableEbsEncryptionByDefaultResponse'
  { -- | The updated status of encryption by default.
    EnableEbsEncryptionByDefaultResponse -> Maybe Bool
ebsEncryptionByDefault :: Prelude.Maybe Prelude.Bool,
    -- | The response's http status code.
    EnableEbsEncryptionByDefaultResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (EnableEbsEncryptionByDefaultResponse
-> EnableEbsEncryptionByDefaultResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableEbsEncryptionByDefaultResponse
-> EnableEbsEncryptionByDefaultResponse -> Bool
$c/= :: EnableEbsEncryptionByDefaultResponse
-> EnableEbsEncryptionByDefaultResponse -> Bool
== :: EnableEbsEncryptionByDefaultResponse
-> EnableEbsEncryptionByDefaultResponse -> Bool
$c== :: EnableEbsEncryptionByDefaultResponse
-> EnableEbsEncryptionByDefaultResponse -> Bool
Prelude.Eq, ReadPrec [EnableEbsEncryptionByDefaultResponse]
ReadPrec EnableEbsEncryptionByDefaultResponse
Int -> ReadS EnableEbsEncryptionByDefaultResponse
ReadS [EnableEbsEncryptionByDefaultResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableEbsEncryptionByDefaultResponse]
$creadListPrec :: ReadPrec [EnableEbsEncryptionByDefaultResponse]
readPrec :: ReadPrec EnableEbsEncryptionByDefaultResponse
$creadPrec :: ReadPrec EnableEbsEncryptionByDefaultResponse
readList :: ReadS [EnableEbsEncryptionByDefaultResponse]
$creadList :: ReadS [EnableEbsEncryptionByDefaultResponse]
readsPrec :: Int -> ReadS EnableEbsEncryptionByDefaultResponse
$creadsPrec :: Int -> ReadS EnableEbsEncryptionByDefaultResponse
Prelude.Read, Int -> EnableEbsEncryptionByDefaultResponse -> ShowS
[EnableEbsEncryptionByDefaultResponse] -> ShowS
EnableEbsEncryptionByDefaultResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableEbsEncryptionByDefaultResponse] -> ShowS
$cshowList :: [EnableEbsEncryptionByDefaultResponse] -> ShowS
show :: EnableEbsEncryptionByDefaultResponse -> String
$cshow :: EnableEbsEncryptionByDefaultResponse -> String
showsPrec :: Int -> EnableEbsEncryptionByDefaultResponse -> ShowS
$cshowsPrec :: Int -> EnableEbsEncryptionByDefaultResponse -> ShowS
Prelude.Show, forall x.
Rep EnableEbsEncryptionByDefaultResponse x
-> EnableEbsEncryptionByDefaultResponse
forall x.
EnableEbsEncryptionByDefaultResponse
-> Rep EnableEbsEncryptionByDefaultResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EnableEbsEncryptionByDefaultResponse x
-> EnableEbsEncryptionByDefaultResponse
$cfrom :: forall x.
EnableEbsEncryptionByDefaultResponse
-> Rep EnableEbsEncryptionByDefaultResponse x
Prelude.Generic)

-- |
-- Create a value of 'EnableEbsEncryptionByDefaultResponse' 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:
--
-- 'ebsEncryptionByDefault', 'enableEbsEncryptionByDefaultResponse_ebsEncryptionByDefault' - The updated status of encryption by default.
--
-- 'httpStatus', 'enableEbsEncryptionByDefaultResponse_httpStatus' - The response's http status code.
newEnableEbsEncryptionByDefaultResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  EnableEbsEncryptionByDefaultResponse
newEnableEbsEncryptionByDefaultResponse :: Int -> EnableEbsEncryptionByDefaultResponse
newEnableEbsEncryptionByDefaultResponse Int
pHttpStatus_ =
  EnableEbsEncryptionByDefaultResponse'
    { $sel:ebsEncryptionByDefault:EnableEbsEncryptionByDefaultResponse' :: Maybe Bool
ebsEncryptionByDefault =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:EnableEbsEncryptionByDefaultResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The updated status of encryption by default.
enableEbsEncryptionByDefaultResponse_ebsEncryptionByDefault :: Lens.Lens' EnableEbsEncryptionByDefaultResponse (Prelude.Maybe Prelude.Bool)
enableEbsEncryptionByDefaultResponse_ebsEncryptionByDefault :: Lens' EnableEbsEncryptionByDefaultResponse (Maybe Bool)
enableEbsEncryptionByDefaultResponse_ebsEncryptionByDefault = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableEbsEncryptionByDefaultResponse' {Maybe Bool
ebsEncryptionByDefault :: Maybe Bool
$sel:ebsEncryptionByDefault:EnableEbsEncryptionByDefaultResponse' :: EnableEbsEncryptionByDefaultResponse -> Maybe Bool
ebsEncryptionByDefault} -> Maybe Bool
ebsEncryptionByDefault) (\s :: EnableEbsEncryptionByDefaultResponse
s@EnableEbsEncryptionByDefaultResponse' {} Maybe Bool
a -> EnableEbsEncryptionByDefaultResponse
s {$sel:ebsEncryptionByDefault:EnableEbsEncryptionByDefaultResponse' :: Maybe Bool
ebsEncryptionByDefault = Maybe Bool
a} :: EnableEbsEncryptionByDefaultResponse)

-- | The response's http status code.
enableEbsEncryptionByDefaultResponse_httpStatus :: Lens.Lens' EnableEbsEncryptionByDefaultResponse Prelude.Int
enableEbsEncryptionByDefaultResponse_httpStatus :: Lens' EnableEbsEncryptionByDefaultResponse Int
enableEbsEncryptionByDefaultResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableEbsEncryptionByDefaultResponse' {Int
httpStatus :: Int
$sel:httpStatus:EnableEbsEncryptionByDefaultResponse' :: EnableEbsEncryptionByDefaultResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: EnableEbsEncryptionByDefaultResponse
s@EnableEbsEncryptionByDefaultResponse' {} Int
a -> EnableEbsEncryptionByDefaultResponse
s {$sel:httpStatus:EnableEbsEncryptionByDefaultResponse' :: Int
httpStatus = Int
a} :: EnableEbsEncryptionByDefaultResponse)

instance
  Prelude.NFData
    EnableEbsEncryptionByDefaultResponse
  where
  rnf :: EnableEbsEncryptionByDefaultResponse -> ()
rnf EnableEbsEncryptionByDefaultResponse' {Int
Maybe Bool
httpStatus :: Int
ebsEncryptionByDefault :: Maybe Bool
$sel:httpStatus:EnableEbsEncryptionByDefaultResponse' :: EnableEbsEncryptionByDefaultResponse -> Int
$sel:ebsEncryptionByDefault:EnableEbsEncryptionByDefaultResponse' :: EnableEbsEncryptionByDefaultResponse -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
ebsEncryptionByDefault
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus