{-# 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.AllocatePublicVirtualInterface
-- 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 public virtual interface to be owned by the specified
-- Amazon Web Services account.
--
-- The owner of a connection calls this function to provision a public
-- virtual interface to be owned by the specified Amazon Web Services
-- account.
--
-- Virtual interfaces created using this function must be confirmed by the
-- owner using ConfirmPublicVirtualInterface. Until this step has been
-- completed, the virtual interface is in the @confirming@ state and is not
-- available to handle traffic.
--
-- When creating an IPv6 public virtual interface, omit the Amazon address
-- and customer address. IPv6 addresses are automatically assigned from the
-- Amazon pool of IPv6 addresses; you cannot specify custom IPv6 addresses.
module Amazonka.DirectConnect.AllocatePublicVirtualInterface
  ( -- * Creating a Request
    AllocatePublicVirtualInterface (..),
    newAllocatePublicVirtualInterface,

    -- * Request Lenses
    allocatePublicVirtualInterface_connectionId,
    allocatePublicVirtualInterface_ownerAccount,
    allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation,

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

-- |
-- Create a value of 'AllocatePublicVirtualInterface' 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', 'allocatePublicVirtualInterface_connectionId' - The ID of the connection on which the public virtual interface is
-- provisioned.
--
-- 'ownerAccount', 'allocatePublicVirtualInterface_ownerAccount' - The ID of the Amazon Web Services account that owns the public virtual
-- interface.
--
-- 'newPublicVirtualInterfaceAllocation'', 'allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation' - Information about the public virtual interface.
newAllocatePublicVirtualInterface ::
  -- | 'connectionId'
  Prelude.Text ->
  -- | 'ownerAccount'
  Prelude.Text ->
  -- | 'newPublicVirtualInterfaceAllocation''
  NewPublicVirtualInterfaceAllocation ->
  AllocatePublicVirtualInterface
newAllocatePublicVirtualInterface :: Text
-> Text
-> NewPublicVirtualInterfaceAllocation
-> AllocatePublicVirtualInterface
newAllocatePublicVirtualInterface
  Text
pConnectionId_
  Text
pOwnerAccount_
  NewPublicVirtualInterfaceAllocation
pNewPublicVirtualInterfaceAllocation_ =
    AllocatePublicVirtualInterface' :: Text
-> Text
-> NewPublicVirtualInterfaceAllocation
-> AllocatePublicVirtualInterface
AllocatePublicVirtualInterface'
      { $sel:connectionId:AllocatePublicVirtualInterface' :: Text
connectionId =
          Text
pConnectionId_,
        $sel:ownerAccount:AllocatePublicVirtualInterface' :: Text
ownerAccount = Text
pOwnerAccount_,
        $sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' =
          NewPublicVirtualInterfaceAllocation
pNewPublicVirtualInterfaceAllocation_
      }

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

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

-- | Information about the public virtual interface.
allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation :: Lens.Lens' AllocatePublicVirtualInterface NewPublicVirtualInterfaceAllocation
allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation :: (NewPublicVirtualInterfaceAllocation
 -> f NewPublicVirtualInterfaceAllocation)
-> AllocatePublicVirtualInterface
-> f AllocatePublicVirtualInterface
allocatePublicVirtualInterface_newPublicVirtualInterfaceAllocation = (AllocatePublicVirtualInterface
 -> NewPublicVirtualInterfaceAllocation)
-> (AllocatePublicVirtualInterface
    -> NewPublicVirtualInterfaceAllocation
    -> AllocatePublicVirtualInterface)
-> Lens
     AllocatePublicVirtualInterface
     AllocatePublicVirtualInterface
     NewPublicVirtualInterfaceAllocation
     NewPublicVirtualInterfaceAllocation
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocatePublicVirtualInterface' {NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' :: NewPublicVirtualInterfaceAllocation
$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface
-> NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation'} -> NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation') (\s :: AllocatePublicVirtualInterface
s@AllocatePublicVirtualInterface' {} NewPublicVirtualInterfaceAllocation
a -> AllocatePublicVirtualInterface
s {$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' = NewPublicVirtualInterfaceAllocation
a} :: AllocatePublicVirtualInterface)

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

instance
  Prelude.NFData
    AllocatePublicVirtualInterface

instance
  Core.ToHeaders
    AllocatePublicVirtualInterface
  where
  toHeaders :: AllocatePublicVirtualInterface -> ResponseHeaders
toHeaders =
    ResponseHeaders
-> AllocatePublicVirtualInterface -> 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.AllocatePublicVirtualInterface" ::
                          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 AllocatePublicVirtualInterface where
  toJSON :: AllocatePublicVirtualInterface -> Value
toJSON AllocatePublicVirtualInterface' {Text
NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation' :: NewPublicVirtualInterfaceAllocation
ownerAccount :: Text
connectionId :: Text
$sel:newPublicVirtualInterfaceAllocation':AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface
-> NewPublicVirtualInterfaceAllocation
$sel:ownerAccount:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> Text
$sel:connectionId:AllocatePublicVirtualInterface' :: AllocatePublicVirtualInterface -> 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
"newPublicVirtualInterfaceAllocation"
                  Text -> NewPublicVirtualInterfaceAllocation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NewPublicVirtualInterfaceAllocation
newPublicVirtualInterfaceAllocation'
              )
          ]
      )

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

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