{-# 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.AssociateVirtualInterface
-- 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)
--
-- Associates a virtual interface with a specified link aggregation group
-- (LAG) or connection. Connectivity to Amazon Web Services is temporarily
-- interrupted as the virtual interface is being migrated. If the target
-- connection or LAG has an associated virtual interface with a conflicting
-- VLAN number or a conflicting IP address, the operation fails.
--
-- Virtual interfaces associated with a hosted connection cannot be
-- associated with a LAG; hosted connections must be migrated along with
-- their virtual interfaces using AssociateHostedConnection.
--
-- To reassociate a virtual interface to a new connection or LAG, the
-- requester must own either the virtual interface itself or the connection
-- to which the virtual interface is currently associated. Additionally,
-- the requester must own the connection or LAG for the association.
module Amazonka.DirectConnect.AssociateVirtualInterface
  ( -- * Creating a Request
    AssociateVirtualInterface (..),
    newAssociateVirtualInterface,

    -- * Request Lenses
    associateVirtualInterface_virtualInterfaceId,
    associateVirtualInterface_connectionId,

    -- * 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:/ 'newAssociateVirtualInterface' smart constructor.
data AssociateVirtualInterface = AssociateVirtualInterface'
  { -- | The ID of the virtual interface.
    AssociateVirtualInterface -> Text
virtualInterfaceId :: Prelude.Text,
    -- | The ID of the LAG or connection.
    AssociateVirtualInterface -> Text
connectionId :: Prelude.Text
  }
  deriving (AssociateVirtualInterface -> AssociateVirtualInterface -> Bool
(AssociateVirtualInterface -> AssociateVirtualInterface -> Bool)
-> (AssociateVirtualInterface -> AssociateVirtualInterface -> Bool)
-> Eq AssociateVirtualInterface
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateVirtualInterface -> AssociateVirtualInterface -> Bool
$c/= :: AssociateVirtualInterface -> AssociateVirtualInterface -> Bool
== :: AssociateVirtualInterface -> AssociateVirtualInterface -> Bool
$c== :: AssociateVirtualInterface -> AssociateVirtualInterface -> Bool
Prelude.Eq, ReadPrec [AssociateVirtualInterface]
ReadPrec AssociateVirtualInterface
Int -> ReadS AssociateVirtualInterface
ReadS [AssociateVirtualInterface]
(Int -> ReadS AssociateVirtualInterface)
-> ReadS [AssociateVirtualInterface]
-> ReadPrec AssociateVirtualInterface
-> ReadPrec [AssociateVirtualInterface]
-> Read AssociateVirtualInterface
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateVirtualInterface]
$creadListPrec :: ReadPrec [AssociateVirtualInterface]
readPrec :: ReadPrec AssociateVirtualInterface
$creadPrec :: ReadPrec AssociateVirtualInterface
readList :: ReadS [AssociateVirtualInterface]
$creadList :: ReadS [AssociateVirtualInterface]
readsPrec :: Int -> ReadS AssociateVirtualInterface
$creadsPrec :: Int -> ReadS AssociateVirtualInterface
Prelude.Read, Int -> AssociateVirtualInterface -> ShowS
[AssociateVirtualInterface] -> ShowS
AssociateVirtualInterface -> String
(Int -> AssociateVirtualInterface -> ShowS)
-> (AssociateVirtualInterface -> String)
-> ([AssociateVirtualInterface] -> ShowS)
-> Show AssociateVirtualInterface
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateVirtualInterface] -> ShowS
$cshowList :: [AssociateVirtualInterface] -> ShowS
show :: AssociateVirtualInterface -> String
$cshow :: AssociateVirtualInterface -> String
showsPrec :: Int -> AssociateVirtualInterface -> ShowS
$cshowsPrec :: Int -> AssociateVirtualInterface -> ShowS
Prelude.Show, (forall x.
 AssociateVirtualInterface -> Rep AssociateVirtualInterface x)
-> (forall x.
    Rep AssociateVirtualInterface x -> AssociateVirtualInterface)
-> Generic AssociateVirtualInterface
forall x.
Rep AssociateVirtualInterface x -> AssociateVirtualInterface
forall x.
AssociateVirtualInterface -> Rep AssociateVirtualInterface x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateVirtualInterface x -> AssociateVirtualInterface
$cfrom :: forall x.
AssociateVirtualInterface -> Rep AssociateVirtualInterface x
Prelude.Generic)

-- |
-- Create a value of 'AssociateVirtualInterface' 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:
--
-- 'virtualInterfaceId', 'associateVirtualInterface_virtualInterfaceId' - The ID of the virtual interface.
--
-- 'connectionId', 'associateVirtualInterface_connectionId' - The ID of the LAG or connection.
newAssociateVirtualInterface ::
  -- | 'virtualInterfaceId'
  Prelude.Text ->
  -- | 'connectionId'
  Prelude.Text ->
  AssociateVirtualInterface
newAssociateVirtualInterface :: Text -> Text -> AssociateVirtualInterface
newAssociateVirtualInterface
  Text
pVirtualInterfaceId_
  Text
pConnectionId_ =
    AssociateVirtualInterface' :: Text -> Text -> AssociateVirtualInterface
AssociateVirtualInterface'
      { $sel:virtualInterfaceId:AssociateVirtualInterface' :: Text
virtualInterfaceId =
          Text
pVirtualInterfaceId_,
        $sel:connectionId:AssociateVirtualInterface' :: Text
connectionId = Text
pConnectionId_
      }

-- | The ID of the virtual interface.
associateVirtualInterface_virtualInterfaceId :: Lens.Lens' AssociateVirtualInterface Prelude.Text
associateVirtualInterface_virtualInterfaceId :: (Text -> f Text)
-> AssociateVirtualInterface -> f AssociateVirtualInterface
associateVirtualInterface_virtualInterfaceId = (AssociateVirtualInterface -> Text)
-> (AssociateVirtualInterface -> Text -> AssociateVirtualInterface)
-> Lens
     AssociateVirtualInterface AssociateVirtualInterface Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateVirtualInterface' {Text
virtualInterfaceId :: Text
$sel:virtualInterfaceId:AssociateVirtualInterface' :: AssociateVirtualInterface -> Text
virtualInterfaceId} -> Text
virtualInterfaceId) (\s :: AssociateVirtualInterface
s@AssociateVirtualInterface' {} Text
a -> AssociateVirtualInterface
s {$sel:virtualInterfaceId:AssociateVirtualInterface' :: Text
virtualInterfaceId = Text
a} :: AssociateVirtualInterface)

-- | The ID of the LAG or connection.
associateVirtualInterface_connectionId :: Lens.Lens' AssociateVirtualInterface Prelude.Text
associateVirtualInterface_connectionId :: (Text -> f Text)
-> AssociateVirtualInterface -> f AssociateVirtualInterface
associateVirtualInterface_connectionId = (AssociateVirtualInterface -> Text)
-> (AssociateVirtualInterface -> Text -> AssociateVirtualInterface)
-> Lens
     AssociateVirtualInterface AssociateVirtualInterface Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateVirtualInterface' {Text
connectionId :: Text
$sel:connectionId:AssociateVirtualInterface' :: AssociateVirtualInterface -> Text
connectionId} -> Text
connectionId) (\s :: AssociateVirtualInterface
s@AssociateVirtualInterface' {} Text
a -> AssociateVirtualInterface
s {$sel:connectionId:AssociateVirtualInterface' :: Text
connectionId = Text
a} :: AssociateVirtualInterface)

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

instance Prelude.NFData AssociateVirtualInterface

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

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

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