{-# 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.CreateConnection
-- 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 connection between a customer network and a specific Direct
-- Connect location.
--
-- A connection links your internal network to an Direct Connect location
-- over a standard Ethernet fiber-optic cable. One end of the cable is
-- connected to your router, the other to an Direct Connect router.
--
-- To find the locations for your Region, use DescribeLocations.
--
-- You can automatically add the new connection to a link aggregation group
-- (LAG) by specifying a LAG ID in the request. This ensures that the new
-- connection is allocated on the same Direct Connect endpoint that hosts
-- the specified LAG. If there are no available ports on the endpoint, the
-- request fails and no connection is created.
module Amazonka.DirectConnect.CreateConnection
  ( -- * Creating a Request
    CreateConnection (..),
    newCreateConnection,

    -- * Request Lenses
    createConnection_lagId,
    createConnection_requestMACSec,
    createConnection_providerName,
    createConnection_tags,
    createConnection_location,
    createConnection_bandwidth,
    createConnection_connectionName,

    -- * Destructuring the Response
    Connection (..),
    newConnection,

    -- * Response Lenses
    connection_lagId,
    connection_macSecCapable,
    connection_portEncryptionStatus,
    connection_vlan,
    connection_location,
    connection_awsDevice,
    connection_hasLogicalRedundancy,
    connection_connectionId,
    connection_awsLogicalDeviceId,
    connection_loaIssueTime,
    connection_partnerName,
    connection_connectionName,
    connection_encryptionMode,
    connection_bandwidth,
    connection_jumboFrameCapable,
    connection_ownerAccount,
    connection_region,
    connection_macSecKeys,
    connection_providerName,
    connection_awsDeviceV2,
    connection_connectionState,
    connection_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:/ 'newCreateConnection' smart constructor.
data CreateConnection = CreateConnection'
  { -- | The ID of the LAG.
    CreateConnection -> Maybe Text
lagId :: Prelude.Maybe Prelude.Text,
    -- | Indicates whether you want the connection to support MAC Security
    -- (MACsec).
    --
    -- MAC Security (MACsec) is only available on dedicated connections. For
    -- information about MAC Security (MACsec) prerequisties, see
    -- <https://docs.aws.amazon.com/directconnect/latest/UserGuide/direct-connect-mac-sec-getting-started.html#mac-sec-prerequisites MACsec prerequisties>
    -- in the /Direct Connect User Guide/.
    CreateConnection -> Maybe Bool
requestMACSec :: Prelude.Maybe Prelude.Bool,
    -- | The name of the service provider associated with the requested
    -- connection.
    CreateConnection -> Maybe Text
providerName :: Prelude.Maybe Prelude.Text,
    -- | The tags to associate with the lag.
    CreateConnection -> Maybe (NonEmpty Tag)
tags :: Prelude.Maybe (Prelude.NonEmpty Tag),
    -- | The location of the connection.
    CreateConnection -> Text
location :: Prelude.Text,
    -- | The bandwidth of the connection.
    CreateConnection -> Text
bandwidth :: Prelude.Text,
    -- | The name of the connection.
    CreateConnection -> Text
connectionName :: Prelude.Text
  }
  deriving (CreateConnection -> CreateConnection -> Bool
(CreateConnection -> CreateConnection -> Bool)
-> (CreateConnection -> CreateConnection -> Bool)
-> Eq CreateConnection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateConnection -> CreateConnection -> Bool
$c/= :: CreateConnection -> CreateConnection -> Bool
== :: CreateConnection -> CreateConnection -> Bool
$c== :: CreateConnection -> CreateConnection -> Bool
Prelude.Eq, ReadPrec [CreateConnection]
ReadPrec CreateConnection
Int -> ReadS CreateConnection
ReadS [CreateConnection]
(Int -> ReadS CreateConnection)
-> ReadS [CreateConnection]
-> ReadPrec CreateConnection
-> ReadPrec [CreateConnection]
-> Read CreateConnection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateConnection]
$creadListPrec :: ReadPrec [CreateConnection]
readPrec :: ReadPrec CreateConnection
$creadPrec :: ReadPrec CreateConnection
readList :: ReadS [CreateConnection]
$creadList :: ReadS [CreateConnection]
readsPrec :: Int -> ReadS CreateConnection
$creadsPrec :: Int -> ReadS CreateConnection
Prelude.Read, Int -> CreateConnection -> ShowS
[CreateConnection] -> ShowS
CreateConnection -> String
(Int -> CreateConnection -> ShowS)
-> (CreateConnection -> String)
-> ([CreateConnection] -> ShowS)
-> Show CreateConnection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateConnection] -> ShowS
$cshowList :: [CreateConnection] -> ShowS
show :: CreateConnection -> String
$cshow :: CreateConnection -> String
showsPrec :: Int -> CreateConnection -> ShowS
$cshowsPrec :: Int -> CreateConnection -> ShowS
Prelude.Show, (forall x. CreateConnection -> Rep CreateConnection x)
-> (forall x. Rep CreateConnection x -> CreateConnection)
-> Generic CreateConnection
forall x. Rep CreateConnection x -> CreateConnection
forall x. CreateConnection -> Rep CreateConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateConnection x -> CreateConnection
$cfrom :: forall x. CreateConnection -> Rep CreateConnection x
Prelude.Generic)

-- |
-- Create a value of 'CreateConnection' 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:
--
-- 'lagId', 'createConnection_lagId' - The ID of the LAG.
--
-- 'requestMACSec', 'createConnection_requestMACSec' - Indicates whether you want the connection to support MAC Security
-- (MACsec).
--
-- MAC Security (MACsec) is only available on dedicated connections. For
-- information about MAC Security (MACsec) prerequisties, see
-- <https://docs.aws.amazon.com/directconnect/latest/UserGuide/direct-connect-mac-sec-getting-started.html#mac-sec-prerequisites MACsec prerequisties>
-- in the /Direct Connect User Guide/.
--
-- 'providerName', 'createConnection_providerName' - The name of the service provider associated with the requested
-- connection.
--
-- 'tags', 'createConnection_tags' - The tags to associate with the lag.
--
-- 'location', 'createConnection_location' - The location of the connection.
--
-- 'bandwidth', 'createConnection_bandwidth' - The bandwidth of the connection.
--
-- 'connectionName', 'createConnection_connectionName' - The name of the connection.
newCreateConnection ::
  -- | 'location'
  Prelude.Text ->
  -- | 'bandwidth'
  Prelude.Text ->
  -- | 'connectionName'
  Prelude.Text ->
  CreateConnection
newCreateConnection :: Text -> Text -> Text -> CreateConnection
newCreateConnection
  Text
pLocation_
  Text
pBandwidth_
  Text
pConnectionName_ =
    CreateConnection' :: Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe (NonEmpty Tag)
-> Text
-> Text
-> Text
-> CreateConnection
CreateConnection'
      { $sel:lagId:CreateConnection' :: Maybe Text
lagId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:requestMACSec:CreateConnection' :: Maybe Bool
requestMACSec = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
        $sel:providerName:CreateConnection' :: Maybe Text
providerName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:tags:CreateConnection' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
forall a. Maybe a
Prelude.Nothing,
        $sel:location:CreateConnection' :: Text
location = Text
pLocation_,
        $sel:bandwidth:CreateConnection' :: Text
bandwidth = Text
pBandwidth_,
        $sel:connectionName:CreateConnection' :: Text
connectionName = Text
pConnectionName_
      }

-- | The ID of the LAG.
createConnection_lagId :: Lens.Lens' CreateConnection (Prelude.Maybe Prelude.Text)
createConnection_lagId :: (Maybe Text -> f (Maybe Text))
-> CreateConnection -> f CreateConnection
createConnection_lagId = (CreateConnection -> Maybe Text)
-> (CreateConnection -> Maybe Text -> CreateConnection)
-> Lens CreateConnection CreateConnection (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Maybe Text
lagId :: Maybe Text
$sel:lagId:CreateConnection' :: CreateConnection -> Maybe Text
lagId} -> Maybe Text
lagId) (\s :: CreateConnection
s@CreateConnection' {} Maybe Text
a -> CreateConnection
s {$sel:lagId:CreateConnection' :: Maybe Text
lagId = Maybe Text
a} :: CreateConnection)

-- | Indicates whether you want the connection to support MAC Security
-- (MACsec).
--
-- MAC Security (MACsec) is only available on dedicated connections. For
-- information about MAC Security (MACsec) prerequisties, see
-- <https://docs.aws.amazon.com/directconnect/latest/UserGuide/direct-connect-mac-sec-getting-started.html#mac-sec-prerequisites MACsec prerequisties>
-- in the /Direct Connect User Guide/.
createConnection_requestMACSec :: Lens.Lens' CreateConnection (Prelude.Maybe Prelude.Bool)
createConnection_requestMACSec :: (Maybe Bool -> f (Maybe Bool))
-> CreateConnection -> f CreateConnection
createConnection_requestMACSec = (CreateConnection -> Maybe Bool)
-> (CreateConnection -> Maybe Bool -> CreateConnection)
-> Lens CreateConnection CreateConnection (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Maybe Bool
requestMACSec :: Maybe Bool
$sel:requestMACSec:CreateConnection' :: CreateConnection -> Maybe Bool
requestMACSec} -> Maybe Bool
requestMACSec) (\s :: CreateConnection
s@CreateConnection' {} Maybe Bool
a -> CreateConnection
s {$sel:requestMACSec:CreateConnection' :: Maybe Bool
requestMACSec = Maybe Bool
a} :: CreateConnection)

-- | The name of the service provider associated with the requested
-- connection.
createConnection_providerName :: Lens.Lens' CreateConnection (Prelude.Maybe Prelude.Text)
createConnection_providerName :: (Maybe Text -> f (Maybe Text))
-> CreateConnection -> f CreateConnection
createConnection_providerName = (CreateConnection -> Maybe Text)
-> (CreateConnection -> Maybe Text -> CreateConnection)
-> Lens CreateConnection CreateConnection (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Maybe Text
providerName :: Maybe Text
$sel:providerName:CreateConnection' :: CreateConnection -> Maybe Text
providerName} -> Maybe Text
providerName) (\s :: CreateConnection
s@CreateConnection' {} Maybe Text
a -> CreateConnection
s {$sel:providerName:CreateConnection' :: Maybe Text
providerName = Maybe Text
a} :: CreateConnection)

-- | The tags to associate with the lag.
createConnection_tags :: Lens.Lens' CreateConnection (Prelude.Maybe (Prelude.NonEmpty Tag))
createConnection_tags :: (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> CreateConnection -> f CreateConnection
createConnection_tags = (CreateConnection -> Maybe (NonEmpty Tag))
-> (CreateConnection -> Maybe (NonEmpty Tag) -> CreateConnection)
-> Lens
     CreateConnection
     CreateConnection
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Maybe (NonEmpty Tag)
tags :: Maybe (NonEmpty Tag)
$sel:tags:CreateConnection' :: CreateConnection -> Maybe (NonEmpty Tag)
tags} -> Maybe (NonEmpty Tag)
tags) (\s :: CreateConnection
s@CreateConnection' {} Maybe (NonEmpty Tag)
a -> CreateConnection
s {$sel:tags:CreateConnection' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
a} :: CreateConnection) ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
 -> CreateConnection -> f CreateConnection)
-> ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
    -> Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> CreateConnection
-> f CreateConnection
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag)
-> Iso
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The location of the connection.
createConnection_location :: Lens.Lens' CreateConnection Prelude.Text
createConnection_location :: (Text -> f Text) -> CreateConnection -> f CreateConnection
createConnection_location = (CreateConnection -> Text)
-> (CreateConnection -> Text -> CreateConnection)
-> Lens CreateConnection CreateConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Text
location :: Text
$sel:location:CreateConnection' :: CreateConnection -> Text
location} -> Text
location) (\s :: CreateConnection
s@CreateConnection' {} Text
a -> CreateConnection
s {$sel:location:CreateConnection' :: Text
location = Text
a} :: CreateConnection)

-- | The bandwidth of the connection.
createConnection_bandwidth :: Lens.Lens' CreateConnection Prelude.Text
createConnection_bandwidth :: (Text -> f Text) -> CreateConnection -> f CreateConnection
createConnection_bandwidth = (CreateConnection -> Text)
-> (CreateConnection -> Text -> CreateConnection)
-> Lens CreateConnection CreateConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Text
bandwidth :: Text
$sel:bandwidth:CreateConnection' :: CreateConnection -> Text
bandwidth} -> Text
bandwidth) (\s :: CreateConnection
s@CreateConnection' {} Text
a -> CreateConnection
s {$sel:bandwidth:CreateConnection' :: Text
bandwidth = Text
a} :: CreateConnection)

-- | The name of the connection.
createConnection_connectionName :: Lens.Lens' CreateConnection Prelude.Text
createConnection_connectionName :: (Text -> f Text) -> CreateConnection -> f CreateConnection
createConnection_connectionName = (CreateConnection -> Text)
-> (CreateConnection -> Text -> CreateConnection)
-> Lens CreateConnection CreateConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Text
connectionName :: Text
$sel:connectionName:CreateConnection' :: CreateConnection -> Text
connectionName} -> Text
connectionName) (\s :: CreateConnection
s@CreateConnection' {} Text
a -> CreateConnection
s {$sel:connectionName:CreateConnection' :: Text
connectionName = Text
a} :: CreateConnection)

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

instance Prelude.Hashable CreateConnection

instance Prelude.NFData CreateConnection

instance Core.ToHeaders CreateConnection where
  toHeaders :: CreateConnection -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateConnection -> 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.CreateConnection" ::
                          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 CreateConnection where
  toJSON :: CreateConnection -> Value
toJSON CreateConnection' {Maybe Bool
Maybe (NonEmpty Tag)
Maybe Text
Text
connectionName :: Text
bandwidth :: Text
location :: Text
tags :: Maybe (NonEmpty Tag)
providerName :: Maybe Text
requestMACSec :: Maybe Bool
lagId :: Maybe Text
$sel:connectionName:CreateConnection' :: CreateConnection -> Text
$sel:bandwidth:CreateConnection' :: CreateConnection -> Text
$sel:location:CreateConnection' :: CreateConnection -> Text
$sel:tags:CreateConnection' :: CreateConnection -> Maybe (NonEmpty Tag)
$sel:providerName:CreateConnection' :: CreateConnection -> Maybe Text
$sel:requestMACSec:CreateConnection' :: CreateConnection -> Maybe Bool
$sel:lagId:CreateConnection' :: CreateConnection -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"lagId" 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
lagId,
            (Text
"requestMACSec" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
requestMACSec,
            (Text
"providerName" 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
providerName,
            (Text
"tags" Text -> NonEmpty Tag -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Tag -> Pair) -> Maybe (NonEmpty Tag) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Tag)
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"location" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
location),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"bandwidth" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
bandwidth),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"connectionName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
connectionName)
          ]
      )

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

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