{-# 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.DirectConnect.AllocatePrivateVirtualInterface
-- 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)
--
-- Provisions a private virtual interface to be owned by the specified
-- Amazon Web Services account.
--
-- Virtual interfaces created using this action must be confirmed by the
-- owner using ConfirmPrivateVirtualInterface. Until then, the virtual
-- interface is in the @Confirming@ state and is not available to handle
-- traffic.
module Amazonka.DirectConnect.AllocatePrivateVirtualInterface
  ( -- * Creating a Request
    AllocatePrivateVirtualInterface (..),
    newAllocatePrivateVirtualInterface,

    -- * Request Lenses
    allocatePrivateVirtualInterface_connectionId,
    allocatePrivateVirtualInterface_ownerAccount,
    allocatePrivateVirtualInterface_newPrivateVirtualInterfaceAllocation,

    -- * Destructuring the Response
    VirtualInterface (..),
    newVirtualInterface,

    -- * Response Lenses
    virtualInterface_bgpPeers,
    virtualInterface_virtualGatewayId,
    virtualInterface_mtu,
    virtualInterface_routeFilterPrefixes,
    virtualInterface_customerAddress,
    virtualInterface_vlan,
    virtualInterface_location,
    virtualInterface_amazonAddress,
    virtualInterface_addressFamily,
    virtualInterface_virtualInterfaceState,
    virtualInterface_connectionId,
    virtualInterface_awsLogicalDeviceId,
    virtualInterface_directConnectGatewayId,
    virtualInterface_amazonSideAsn,
    virtualInterface_virtualInterfaceType,
    virtualInterface_asn,
    virtualInterface_authKey,
    virtualInterface_jumboFrameCapable,
    virtualInterface_customerRouterConfig,
    virtualInterface_ownerAccount,
    virtualInterface_region,
    virtualInterface_virtualInterfaceName,
    virtualInterface_awsDeviceV2,
    virtualInterface_virtualInterfaceId,
    virtualInterface_tags,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DirectConnect.Types
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:/ 'newAllocatePrivateVirtualInterface' smart constructor.
data AllocatePrivateVirtualInterface = AllocatePrivateVirtualInterface'
  { -- | The ID of the connection on which the private virtual interface is
    -- provisioned.
    AllocatePrivateVirtualInterface -> Text
connectionId :: Prelude.Text,
    -- | The ID of the Amazon Web Services account that owns the virtual private
    -- interface.
    AllocatePrivateVirtualInterface -> Text
ownerAccount :: Prelude.Text,
    -- | Information about the private virtual interface.
    AllocatePrivateVirtualInterface
-> NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation' :: NewPrivateVirtualInterfaceAllocation
  }
  deriving (AllocatePrivateVirtualInterface
-> AllocatePrivateVirtualInterface -> Bool
(AllocatePrivateVirtualInterface
 -> AllocatePrivateVirtualInterface -> Bool)
-> (AllocatePrivateVirtualInterface
    -> AllocatePrivateVirtualInterface -> Bool)
-> Eq AllocatePrivateVirtualInterface
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AllocatePrivateVirtualInterface
-> AllocatePrivateVirtualInterface -> Bool
$c/= :: AllocatePrivateVirtualInterface
-> AllocatePrivateVirtualInterface -> Bool
== :: AllocatePrivateVirtualInterface
-> AllocatePrivateVirtualInterface -> Bool
$c== :: AllocatePrivateVirtualInterface
-> AllocatePrivateVirtualInterface -> Bool
Prelude.Eq, ReadPrec [AllocatePrivateVirtualInterface]
ReadPrec AllocatePrivateVirtualInterface
Int -> ReadS AllocatePrivateVirtualInterface
ReadS [AllocatePrivateVirtualInterface]
(Int -> ReadS AllocatePrivateVirtualInterface)
-> ReadS [AllocatePrivateVirtualInterface]
-> ReadPrec AllocatePrivateVirtualInterface
-> ReadPrec [AllocatePrivateVirtualInterface]
-> Read AllocatePrivateVirtualInterface
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AllocatePrivateVirtualInterface]
$creadListPrec :: ReadPrec [AllocatePrivateVirtualInterface]
readPrec :: ReadPrec AllocatePrivateVirtualInterface
$creadPrec :: ReadPrec AllocatePrivateVirtualInterface
readList :: ReadS [AllocatePrivateVirtualInterface]
$creadList :: ReadS [AllocatePrivateVirtualInterface]
readsPrec :: Int -> ReadS AllocatePrivateVirtualInterface
$creadsPrec :: Int -> ReadS AllocatePrivateVirtualInterface
Prelude.Read, Int -> AllocatePrivateVirtualInterface -> ShowS
[AllocatePrivateVirtualInterface] -> ShowS
AllocatePrivateVirtualInterface -> String
(Int -> AllocatePrivateVirtualInterface -> ShowS)
-> (AllocatePrivateVirtualInterface -> String)
-> ([AllocatePrivateVirtualInterface] -> ShowS)
-> Show AllocatePrivateVirtualInterface
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AllocatePrivateVirtualInterface] -> ShowS
$cshowList :: [AllocatePrivateVirtualInterface] -> ShowS
show :: AllocatePrivateVirtualInterface -> String
$cshow :: AllocatePrivateVirtualInterface -> String
showsPrec :: Int -> AllocatePrivateVirtualInterface -> ShowS
$cshowsPrec :: Int -> AllocatePrivateVirtualInterface -> ShowS
Prelude.Show, (forall x.
 AllocatePrivateVirtualInterface
 -> Rep AllocatePrivateVirtualInterface x)
-> (forall x.
    Rep AllocatePrivateVirtualInterface x
    -> AllocatePrivateVirtualInterface)
-> Generic AllocatePrivateVirtualInterface
forall x.
Rep AllocatePrivateVirtualInterface x
-> AllocatePrivateVirtualInterface
forall x.
AllocatePrivateVirtualInterface
-> Rep AllocatePrivateVirtualInterface x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AllocatePrivateVirtualInterface x
-> AllocatePrivateVirtualInterface
$cfrom :: forall x.
AllocatePrivateVirtualInterface
-> Rep AllocatePrivateVirtualInterface x
Prelude.Generic)

-- |
-- Create a value of 'AllocatePrivateVirtualInterface' 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:
--
-- 'connectionId', 'allocatePrivateVirtualInterface_connectionId' - The ID of the connection on which the private virtual interface is
-- provisioned.
--
-- 'ownerAccount', 'allocatePrivateVirtualInterface_ownerAccount' - The ID of the Amazon Web Services account that owns the virtual private
-- interface.
--
-- 'newPrivateVirtualInterfaceAllocation'', 'allocatePrivateVirtualInterface_newPrivateVirtualInterfaceAllocation' - Information about the private virtual interface.
newAllocatePrivateVirtualInterface ::
  -- | 'connectionId'
  Prelude.Text ->
  -- | 'ownerAccount'
  Prelude.Text ->
  -- | 'newPrivateVirtualInterfaceAllocation''
  NewPrivateVirtualInterfaceAllocation ->
  AllocatePrivateVirtualInterface
newAllocatePrivateVirtualInterface :: Text
-> Text
-> NewPrivateVirtualInterfaceAllocation
-> AllocatePrivateVirtualInterface
newAllocatePrivateVirtualInterface
  Text
pConnectionId_
  Text
pOwnerAccount_
  NewPrivateVirtualInterfaceAllocation
pNewPrivateVirtualInterfaceAllocation_ =
    AllocatePrivateVirtualInterface' :: Text
-> Text
-> NewPrivateVirtualInterfaceAllocation
-> AllocatePrivateVirtualInterface
AllocatePrivateVirtualInterface'
      { $sel:connectionId:AllocatePrivateVirtualInterface' :: Text
connectionId =
          Text
pConnectionId_,
        $sel:ownerAccount:AllocatePrivateVirtualInterface' :: Text
ownerAccount = Text
pOwnerAccount_,
        $sel:newPrivateVirtualInterfaceAllocation':AllocatePrivateVirtualInterface' :: NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation' =
          NewPrivateVirtualInterfaceAllocation
pNewPrivateVirtualInterfaceAllocation_
      }

-- | The ID of the connection on which the private virtual interface is
-- provisioned.
allocatePrivateVirtualInterface_connectionId :: Lens.Lens' AllocatePrivateVirtualInterface Prelude.Text
allocatePrivateVirtualInterface_connectionId :: (Text -> f Text)
-> AllocatePrivateVirtualInterface
-> f AllocatePrivateVirtualInterface
allocatePrivateVirtualInterface_connectionId = (AllocatePrivateVirtualInterface -> Text)
-> (AllocatePrivateVirtualInterface
    -> Text -> AllocatePrivateVirtualInterface)
-> Lens
     AllocatePrivateVirtualInterface
     AllocatePrivateVirtualInterface
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocatePrivateVirtualInterface' {Text
connectionId :: Text
$sel:connectionId:AllocatePrivateVirtualInterface' :: AllocatePrivateVirtualInterface -> Text
connectionId} -> Text
connectionId) (\s :: AllocatePrivateVirtualInterface
s@AllocatePrivateVirtualInterface' {} Text
a -> AllocatePrivateVirtualInterface
s {$sel:connectionId:AllocatePrivateVirtualInterface' :: Text
connectionId = Text
a} :: AllocatePrivateVirtualInterface)

-- | The ID of the Amazon Web Services account that owns the virtual private
-- interface.
allocatePrivateVirtualInterface_ownerAccount :: Lens.Lens' AllocatePrivateVirtualInterface Prelude.Text
allocatePrivateVirtualInterface_ownerAccount :: (Text -> f Text)
-> AllocatePrivateVirtualInterface
-> f AllocatePrivateVirtualInterface
allocatePrivateVirtualInterface_ownerAccount = (AllocatePrivateVirtualInterface -> Text)
-> (AllocatePrivateVirtualInterface
    -> Text -> AllocatePrivateVirtualInterface)
-> Lens
     AllocatePrivateVirtualInterface
     AllocatePrivateVirtualInterface
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocatePrivateVirtualInterface' {Text
ownerAccount :: Text
$sel:ownerAccount:AllocatePrivateVirtualInterface' :: AllocatePrivateVirtualInterface -> Text
ownerAccount} -> Text
ownerAccount) (\s :: AllocatePrivateVirtualInterface
s@AllocatePrivateVirtualInterface' {} Text
a -> AllocatePrivateVirtualInterface
s {$sel:ownerAccount:AllocatePrivateVirtualInterface' :: Text
ownerAccount = Text
a} :: AllocatePrivateVirtualInterface)

-- | Information about the private virtual interface.
allocatePrivateVirtualInterface_newPrivateVirtualInterfaceAllocation :: Lens.Lens' AllocatePrivateVirtualInterface NewPrivateVirtualInterfaceAllocation
allocatePrivateVirtualInterface_newPrivateVirtualInterfaceAllocation :: (NewPrivateVirtualInterfaceAllocation
 -> f NewPrivateVirtualInterfaceAllocation)
-> AllocatePrivateVirtualInterface
-> f AllocatePrivateVirtualInterface
allocatePrivateVirtualInterface_newPrivateVirtualInterfaceAllocation = (AllocatePrivateVirtualInterface
 -> NewPrivateVirtualInterfaceAllocation)
-> (AllocatePrivateVirtualInterface
    -> NewPrivateVirtualInterfaceAllocation
    -> AllocatePrivateVirtualInterface)
-> Lens
     AllocatePrivateVirtualInterface
     AllocatePrivateVirtualInterface
     NewPrivateVirtualInterfaceAllocation
     NewPrivateVirtualInterfaceAllocation
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocatePrivateVirtualInterface' {NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation' :: NewPrivateVirtualInterfaceAllocation
$sel:newPrivateVirtualInterfaceAllocation':AllocatePrivateVirtualInterface' :: AllocatePrivateVirtualInterface
-> NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation'} -> NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation') (\s :: AllocatePrivateVirtualInterface
s@AllocatePrivateVirtualInterface' {} NewPrivateVirtualInterfaceAllocation
a -> AllocatePrivateVirtualInterface
s {$sel:newPrivateVirtualInterfaceAllocation':AllocatePrivateVirtualInterface' :: NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation' = NewPrivateVirtualInterfaceAllocation
a} :: AllocatePrivateVirtualInterface)

instance
  Core.AWSRequest
    AllocatePrivateVirtualInterface
  where
  type
    AWSResponse AllocatePrivateVirtualInterface =
      VirtualInterface
  request :: AllocatePrivateVirtualInterface
-> Request AllocatePrivateVirtualInterface
request = Service
-> AllocatePrivateVirtualInterface
-> Request AllocatePrivateVirtualInterface
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AllocatePrivateVirtualInterface
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse AllocatePrivateVirtualInterface)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AllocatePrivateVirtualInterface))
-> Logger
-> Service
-> Proxy AllocatePrivateVirtualInterface
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse AllocatePrivateVirtualInterface)))
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 -> Object -> Either String VirtualInterface
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance
  Prelude.Hashable
    AllocatePrivateVirtualInterface

instance
  Prelude.NFData
    AllocatePrivateVirtualInterface

instance
  Core.ToHeaders
    AllocatePrivateVirtualInterface
  where
  toHeaders :: AllocatePrivateVirtualInterface -> ResponseHeaders
toHeaders =
    ResponseHeaders
-> AllocatePrivateVirtualInterface -> 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
"OvertureService.AllocatePrivateVirtualInterface" ::
                          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 AllocatePrivateVirtualInterface where
  toJSON :: AllocatePrivateVirtualInterface -> Value
toJSON AllocatePrivateVirtualInterface' {Text
NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation' :: NewPrivateVirtualInterfaceAllocation
ownerAccount :: Text
connectionId :: Text
$sel:newPrivateVirtualInterfaceAllocation':AllocatePrivateVirtualInterface' :: AllocatePrivateVirtualInterface
-> NewPrivateVirtualInterfaceAllocation
$sel:ownerAccount:AllocatePrivateVirtualInterface' :: AllocatePrivateVirtualInterface -> Text
$sel:connectionId:AllocatePrivateVirtualInterface' :: AllocatePrivateVirtualInterface -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"connectionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
connectionId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ownerAccount" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ownerAccount),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"newPrivateVirtualInterfaceAllocation"
                  Text -> NewPrivateVirtualInterfaceAllocation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NewPrivateVirtualInterfaceAllocation
newPrivateVirtualInterfaceAllocation'
              )
          ]
      )

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

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