{-# 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.CloudHSMV2.CreateHsm
-- 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)
--
-- Creates a new hardware security module (HSM) in the specified AWS
-- CloudHSM cluster.
module Amazonka.CloudHSMV2.CreateHsm
  ( -- * Creating a Request
    CreateHsm (..),
    newCreateHsm,

    -- * Request Lenses
    createHsm_ipAddress,
    createHsm_clusterId,
    createHsm_availabilityZone,

    -- * Destructuring the Response
    CreateHsmResponse (..),
    newCreateHsmResponse,

    -- * Response Lenses
    createHsmResponse_hsm,
    createHsmResponse_httpStatus,
  )
where

import Amazonka.CloudHSMV2.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateHsm' smart constructor.
data CreateHsm = CreateHsm'
  { -- | The HSM\'s IP address. If you specify an IP address, use an available
    -- address from the subnet that maps to the Availability Zone where you are
    -- creating the HSM. If you don\'t specify an IP address, one is chosen for
    -- you from that subnet.
    CreateHsm -> Maybe Text
ipAddress :: Prelude.Maybe Prelude.Text,
    -- | The identifier (ID) of the HSM\'s cluster. To find the cluster ID, use
    -- DescribeClusters.
    CreateHsm -> Text
clusterId :: Prelude.Text,
    -- | The Availability Zone where you are creating the HSM. To find the
    -- cluster\'s Availability Zones, use DescribeClusters.
    CreateHsm -> Text
availabilityZone :: Prelude.Text
  }
  deriving (CreateHsm -> CreateHsm -> Bool
(CreateHsm -> CreateHsm -> Bool)
-> (CreateHsm -> CreateHsm -> Bool) -> Eq CreateHsm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateHsm -> CreateHsm -> Bool
$c/= :: CreateHsm -> CreateHsm -> Bool
== :: CreateHsm -> CreateHsm -> Bool
$c== :: CreateHsm -> CreateHsm -> Bool
Prelude.Eq, ReadPrec [CreateHsm]
ReadPrec CreateHsm
Int -> ReadS CreateHsm
ReadS [CreateHsm]
(Int -> ReadS CreateHsm)
-> ReadS [CreateHsm]
-> ReadPrec CreateHsm
-> ReadPrec [CreateHsm]
-> Read CreateHsm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateHsm]
$creadListPrec :: ReadPrec [CreateHsm]
readPrec :: ReadPrec CreateHsm
$creadPrec :: ReadPrec CreateHsm
readList :: ReadS [CreateHsm]
$creadList :: ReadS [CreateHsm]
readsPrec :: Int -> ReadS CreateHsm
$creadsPrec :: Int -> ReadS CreateHsm
Prelude.Read, Int -> CreateHsm -> ShowS
[CreateHsm] -> ShowS
CreateHsm -> String
(Int -> CreateHsm -> ShowS)
-> (CreateHsm -> String)
-> ([CreateHsm] -> ShowS)
-> Show CreateHsm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateHsm] -> ShowS
$cshowList :: [CreateHsm] -> ShowS
show :: CreateHsm -> String
$cshow :: CreateHsm -> String
showsPrec :: Int -> CreateHsm -> ShowS
$cshowsPrec :: Int -> CreateHsm -> ShowS
Prelude.Show, (forall x. CreateHsm -> Rep CreateHsm x)
-> (forall x. Rep CreateHsm x -> CreateHsm) -> Generic CreateHsm
forall x. Rep CreateHsm x -> CreateHsm
forall x. CreateHsm -> Rep CreateHsm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateHsm x -> CreateHsm
$cfrom :: forall x. CreateHsm -> Rep CreateHsm x
Prelude.Generic)

-- |
-- Create a value of 'CreateHsm' 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:
--
-- 'ipAddress', 'createHsm_ipAddress' - The HSM\'s IP address. If you specify an IP address, use an available
-- address from the subnet that maps to the Availability Zone where you are
-- creating the HSM. If you don\'t specify an IP address, one is chosen for
-- you from that subnet.
--
-- 'clusterId', 'createHsm_clusterId' - The identifier (ID) of the HSM\'s cluster. To find the cluster ID, use
-- DescribeClusters.
--
-- 'availabilityZone', 'createHsm_availabilityZone' - The Availability Zone where you are creating the HSM. To find the
-- cluster\'s Availability Zones, use DescribeClusters.
newCreateHsm ::
  -- | 'clusterId'
  Prelude.Text ->
  -- | 'availabilityZone'
  Prelude.Text ->
  CreateHsm
newCreateHsm :: Text -> Text -> CreateHsm
newCreateHsm Text
pClusterId_ Text
pAvailabilityZone_ =
  CreateHsm' :: Maybe Text -> Text -> Text -> CreateHsm
CreateHsm'
    { $sel:ipAddress:CreateHsm' :: Maybe Text
ipAddress = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:clusterId:CreateHsm' :: Text
clusterId = Text
pClusterId_,
      $sel:availabilityZone:CreateHsm' :: Text
availabilityZone = Text
pAvailabilityZone_
    }

-- | The HSM\'s IP address. If you specify an IP address, use an available
-- address from the subnet that maps to the Availability Zone where you are
-- creating the HSM. If you don\'t specify an IP address, one is chosen for
-- you from that subnet.
createHsm_ipAddress :: Lens.Lens' CreateHsm (Prelude.Maybe Prelude.Text)
createHsm_ipAddress :: (Maybe Text -> f (Maybe Text)) -> CreateHsm -> f CreateHsm
createHsm_ipAddress = (CreateHsm -> Maybe Text)
-> (CreateHsm -> Maybe Text -> CreateHsm)
-> Lens CreateHsm CreateHsm (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateHsm' {Maybe Text
ipAddress :: Maybe Text
$sel:ipAddress:CreateHsm' :: CreateHsm -> Maybe Text
ipAddress} -> Maybe Text
ipAddress) (\s :: CreateHsm
s@CreateHsm' {} Maybe Text
a -> CreateHsm
s {$sel:ipAddress:CreateHsm' :: Maybe Text
ipAddress = Maybe Text
a} :: CreateHsm)

-- | The identifier (ID) of the HSM\'s cluster. To find the cluster ID, use
-- DescribeClusters.
createHsm_clusterId :: Lens.Lens' CreateHsm Prelude.Text
createHsm_clusterId :: (Text -> f Text) -> CreateHsm -> f CreateHsm
createHsm_clusterId = (CreateHsm -> Text)
-> (CreateHsm -> Text -> CreateHsm)
-> Lens CreateHsm CreateHsm Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateHsm' {Text
clusterId :: Text
$sel:clusterId:CreateHsm' :: CreateHsm -> Text
clusterId} -> Text
clusterId) (\s :: CreateHsm
s@CreateHsm' {} Text
a -> CreateHsm
s {$sel:clusterId:CreateHsm' :: Text
clusterId = Text
a} :: CreateHsm)

-- | The Availability Zone where you are creating the HSM. To find the
-- cluster\'s Availability Zones, use DescribeClusters.
createHsm_availabilityZone :: Lens.Lens' CreateHsm Prelude.Text
createHsm_availabilityZone :: (Text -> f Text) -> CreateHsm -> f CreateHsm
createHsm_availabilityZone = (CreateHsm -> Text)
-> (CreateHsm -> Text -> CreateHsm)
-> Lens CreateHsm CreateHsm Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateHsm' {Text
availabilityZone :: Text
$sel:availabilityZone:CreateHsm' :: CreateHsm -> Text
availabilityZone} -> Text
availabilityZone) (\s :: CreateHsm
s@CreateHsm' {} Text
a -> CreateHsm
s {$sel:availabilityZone:CreateHsm' :: Text
availabilityZone = Text
a} :: CreateHsm)

instance Core.AWSRequest CreateHsm where
  type AWSResponse CreateHsm = CreateHsmResponse
  request :: CreateHsm -> Request CreateHsm
request = Service -> CreateHsm -> Request CreateHsm
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateHsm
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateHsm)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateHsm))
-> Logger
-> Service
-> Proxy CreateHsm
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateHsm)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Hsm -> Int -> CreateHsmResponse
CreateHsmResponse'
            (Maybe Hsm -> Int -> CreateHsmResponse)
-> Either String (Maybe Hsm)
-> Either String (Int -> CreateHsmResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Hsm)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Hsm")
            Either String (Int -> CreateHsmResponse)
-> Either String Int -> Either String CreateHsmResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateHsm

instance Prelude.NFData CreateHsm

instance Core.ToHeaders CreateHsm where
  toHeaders :: CreateHsm -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateHsm -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"BaldrApiService.CreateHsm" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateHsm where
  toJSON :: CreateHsm -> Value
toJSON CreateHsm' {Maybe Text
Text
availabilityZone :: Text
clusterId :: Text
ipAddress :: Maybe Text
$sel:availabilityZone:CreateHsm' :: CreateHsm -> Text
$sel:clusterId:CreateHsm' :: CreateHsm -> Text
$sel:ipAddress:CreateHsm' :: CreateHsm -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"IpAddress" 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
ipAddress,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ClusterId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clusterId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AvailabilityZone" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
availabilityZone)
          ]
      )

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

instance Core.ToQuery CreateHsm where
  toQuery :: CreateHsm -> QueryString
toQuery = QueryString -> CreateHsm -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateHsmResponse' smart constructor.
data CreateHsmResponse = CreateHsmResponse'
  { -- | Information about the HSM that was created.
    CreateHsmResponse -> Maybe Hsm
hsm :: Prelude.Maybe Hsm,
    -- | The response's http status code.
    CreateHsmResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateHsmResponse -> CreateHsmResponse -> Bool
(CreateHsmResponse -> CreateHsmResponse -> Bool)
-> (CreateHsmResponse -> CreateHsmResponse -> Bool)
-> Eq CreateHsmResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateHsmResponse -> CreateHsmResponse -> Bool
$c/= :: CreateHsmResponse -> CreateHsmResponse -> Bool
== :: CreateHsmResponse -> CreateHsmResponse -> Bool
$c== :: CreateHsmResponse -> CreateHsmResponse -> Bool
Prelude.Eq, ReadPrec [CreateHsmResponse]
ReadPrec CreateHsmResponse
Int -> ReadS CreateHsmResponse
ReadS [CreateHsmResponse]
(Int -> ReadS CreateHsmResponse)
-> ReadS [CreateHsmResponse]
-> ReadPrec CreateHsmResponse
-> ReadPrec [CreateHsmResponse]
-> Read CreateHsmResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateHsmResponse]
$creadListPrec :: ReadPrec [CreateHsmResponse]
readPrec :: ReadPrec CreateHsmResponse
$creadPrec :: ReadPrec CreateHsmResponse
readList :: ReadS [CreateHsmResponse]
$creadList :: ReadS [CreateHsmResponse]
readsPrec :: Int -> ReadS CreateHsmResponse
$creadsPrec :: Int -> ReadS CreateHsmResponse
Prelude.Read, Int -> CreateHsmResponse -> ShowS
[CreateHsmResponse] -> ShowS
CreateHsmResponse -> String
(Int -> CreateHsmResponse -> ShowS)
-> (CreateHsmResponse -> String)
-> ([CreateHsmResponse] -> ShowS)
-> Show CreateHsmResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateHsmResponse] -> ShowS
$cshowList :: [CreateHsmResponse] -> ShowS
show :: CreateHsmResponse -> String
$cshow :: CreateHsmResponse -> String
showsPrec :: Int -> CreateHsmResponse -> ShowS
$cshowsPrec :: Int -> CreateHsmResponse -> ShowS
Prelude.Show, (forall x. CreateHsmResponse -> Rep CreateHsmResponse x)
-> (forall x. Rep CreateHsmResponse x -> CreateHsmResponse)
-> Generic CreateHsmResponse
forall x. Rep CreateHsmResponse x -> CreateHsmResponse
forall x. CreateHsmResponse -> Rep CreateHsmResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateHsmResponse x -> CreateHsmResponse
$cfrom :: forall x. CreateHsmResponse -> Rep CreateHsmResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateHsmResponse' 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:
--
-- 'hsm', 'createHsmResponse_hsm' - Information about the HSM that was created.
--
-- 'httpStatus', 'createHsmResponse_httpStatus' - The response's http status code.
newCreateHsmResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateHsmResponse
newCreateHsmResponse :: Int -> CreateHsmResponse
newCreateHsmResponse Int
pHttpStatus_ =
  CreateHsmResponse' :: Maybe Hsm -> Int -> CreateHsmResponse
CreateHsmResponse'
    { $sel:hsm:CreateHsmResponse' :: Maybe Hsm
hsm = Maybe Hsm
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateHsmResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the HSM that was created.
createHsmResponse_hsm :: Lens.Lens' CreateHsmResponse (Prelude.Maybe Hsm)
createHsmResponse_hsm :: (Maybe Hsm -> f (Maybe Hsm))
-> CreateHsmResponse -> f CreateHsmResponse
createHsmResponse_hsm = (CreateHsmResponse -> Maybe Hsm)
-> (CreateHsmResponse -> Maybe Hsm -> CreateHsmResponse)
-> Lens CreateHsmResponse CreateHsmResponse (Maybe Hsm) (Maybe Hsm)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateHsmResponse' {Maybe Hsm
hsm :: Maybe Hsm
$sel:hsm:CreateHsmResponse' :: CreateHsmResponse -> Maybe Hsm
hsm} -> Maybe Hsm
hsm) (\s :: CreateHsmResponse
s@CreateHsmResponse' {} Maybe Hsm
a -> CreateHsmResponse
s {$sel:hsm:CreateHsmResponse' :: Maybe Hsm
hsm = Maybe Hsm
a} :: CreateHsmResponse)

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

instance Prelude.NFData CreateHsmResponse