{-# 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.CreateInterconnect
-- 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 an interconnect between an Direct Connect Partner\'s network and
-- a specific Direct Connect location.
--
-- An interconnect is a connection that is capable of hosting other
-- connections. The Direct Connect Partner can use an interconnect to
-- provide Direct Connect hosted connections to customers through their own
-- network services. Like a standard connection, an interconnect links the
-- partner\'s network to an Direct Connect location over a standard
-- Ethernet fiber-optic cable. One end is connected to the partner\'s
-- router, the other to an Direct Connect router.
--
-- You can automatically add the new interconnect to a link aggregation
-- group (LAG) by specifying a LAG ID in the request. This ensures that the
-- new interconnect 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 interconnect is created.
--
-- For each end customer, the Direct Connect Partner provisions a
-- connection on their interconnect by calling AllocateHostedConnection.
-- The end customer can then connect to Amazon Web Services resources by
-- creating a virtual interface on their connection, using the VLAN
-- assigned to them by the Direct Connect Partner.
--
-- Intended for use by Direct Connect Partners only.
module Amazonka.DirectConnect.CreateInterconnect
  ( -- * Creating a Request
    CreateInterconnect (..),
    newCreateInterconnect,

    -- * Request Lenses
    createInterconnect_lagId,
    createInterconnect_providerName,
    createInterconnect_tags,
    createInterconnect_interconnectName,
    createInterconnect_bandwidth,
    createInterconnect_location,

    -- * Destructuring the Response
    Interconnect (..),
    newInterconnect,

    -- * Response Lenses
    interconnect_lagId,
    interconnect_interconnectId,
    interconnect_location,
    interconnect_interconnectName,
    interconnect_awsDevice,
    interconnect_hasLogicalRedundancy,
    interconnect_awsLogicalDeviceId,
    interconnect_loaIssueTime,
    interconnect_bandwidth,
    interconnect_jumboFrameCapable,
    interconnect_interconnectState,
    interconnect_region,
    interconnect_providerName,
    interconnect_awsDeviceV2,
    interconnect_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:/ 'newCreateInterconnect' smart constructor.
data CreateInterconnect = CreateInterconnect'
  { -- | The ID of the LAG.
    CreateInterconnect -> Maybe Text
lagId :: Prelude.Maybe Prelude.Text,
    -- | The name of the service provider associated with the interconnect.
    CreateInterconnect -> Maybe Text
providerName :: Prelude.Maybe Prelude.Text,
    -- | The tags to associate with the interconnect.
    CreateInterconnect -> Maybe (NonEmpty Tag)
tags :: Prelude.Maybe (Prelude.NonEmpty Tag),
    -- | The name of the interconnect.
    CreateInterconnect -> Text
interconnectName :: Prelude.Text,
    -- | The port bandwidth, in Gbps. The possible values are 1 and 10.
    CreateInterconnect -> Text
bandwidth :: Prelude.Text,
    -- | The location of the interconnect.
    CreateInterconnect -> Text
location :: Prelude.Text
  }
  deriving (CreateInterconnect -> CreateInterconnect -> Bool
(CreateInterconnect -> CreateInterconnect -> Bool)
-> (CreateInterconnect -> CreateInterconnect -> Bool)
-> Eq CreateInterconnect
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateInterconnect -> CreateInterconnect -> Bool
$c/= :: CreateInterconnect -> CreateInterconnect -> Bool
== :: CreateInterconnect -> CreateInterconnect -> Bool
$c== :: CreateInterconnect -> CreateInterconnect -> Bool
Prelude.Eq, ReadPrec [CreateInterconnect]
ReadPrec CreateInterconnect
Int -> ReadS CreateInterconnect
ReadS [CreateInterconnect]
(Int -> ReadS CreateInterconnect)
-> ReadS [CreateInterconnect]
-> ReadPrec CreateInterconnect
-> ReadPrec [CreateInterconnect]
-> Read CreateInterconnect
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateInterconnect]
$creadListPrec :: ReadPrec [CreateInterconnect]
readPrec :: ReadPrec CreateInterconnect
$creadPrec :: ReadPrec CreateInterconnect
readList :: ReadS [CreateInterconnect]
$creadList :: ReadS [CreateInterconnect]
readsPrec :: Int -> ReadS CreateInterconnect
$creadsPrec :: Int -> ReadS CreateInterconnect
Prelude.Read, Int -> CreateInterconnect -> ShowS
[CreateInterconnect] -> ShowS
CreateInterconnect -> String
(Int -> CreateInterconnect -> ShowS)
-> (CreateInterconnect -> String)
-> ([CreateInterconnect] -> ShowS)
-> Show CreateInterconnect
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateInterconnect] -> ShowS
$cshowList :: [CreateInterconnect] -> ShowS
show :: CreateInterconnect -> String
$cshow :: CreateInterconnect -> String
showsPrec :: Int -> CreateInterconnect -> ShowS
$cshowsPrec :: Int -> CreateInterconnect -> ShowS
Prelude.Show, (forall x. CreateInterconnect -> Rep CreateInterconnect x)
-> (forall x. Rep CreateInterconnect x -> CreateInterconnect)
-> Generic CreateInterconnect
forall x. Rep CreateInterconnect x -> CreateInterconnect
forall x. CreateInterconnect -> Rep CreateInterconnect x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateInterconnect x -> CreateInterconnect
$cfrom :: forall x. CreateInterconnect -> Rep CreateInterconnect x
Prelude.Generic)

-- |
-- Create a value of 'CreateInterconnect' 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', 'createInterconnect_lagId' - The ID of the LAG.
--
-- 'providerName', 'createInterconnect_providerName' - The name of the service provider associated with the interconnect.
--
-- 'tags', 'createInterconnect_tags' - The tags to associate with the interconnect.
--
-- 'interconnectName', 'createInterconnect_interconnectName' - The name of the interconnect.
--
-- 'bandwidth', 'createInterconnect_bandwidth' - The port bandwidth, in Gbps. The possible values are 1 and 10.
--
-- 'location', 'createInterconnect_location' - The location of the interconnect.
newCreateInterconnect ::
  -- | 'interconnectName'
  Prelude.Text ->
  -- | 'bandwidth'
  Prelude.Text ->
  -- | 'location'
  Prelude.Text ->
  CreateInterconnect
newCreateInterconnect :: Text -> Text -> Text -> CreateInterconnect
newCreateInterconnect
  Text
pInterconnectName_
  Text
pBandwidth_
  Text
pLocation_ =
    CreateInterconnect' :: Maybe Text
-> Maybe Text
-> Maybe (NonEmpty Tag)
-> Text
-> Text
-> Text
-> CreateInterconnect
CreateInterconnect'
      { $sel:lagId:CreateInterconnect' :: Maybe Text
lagId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:providerName:CreateInterconnect' :: Maybe Text
providerName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:tags:CreateInterconnect' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
forall a. Maybe a
Prelude.Nothing,
        $sel:interconnectName:CreateInterconnect' :: Text
interconnectName = Text
pInterconnectName_,
        $sel:bandwidth:CreateInterconnect' :: Text
bandwidth = Text
pBandwidth_,
        $sel:location:CreateInterconnect' :: Text
location = Text
pLocation_
      }

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

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

-- | The tags to associate with the interconnect.
createInterconnect_tags :: Lens.Lens' CreateInterconnect (Prelude.Maybe (Prelude.NonEmpty Tag))
createInterconnect_tags :: (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> CreateInterconnect -> f CreateInterconnect
createInterconnect_tags = (CreateInterconnect -> Maybe (NonEmpty Tag))
-> (CreateInterconnect
    -> Maybe (NonEmpty Tag) -> CreateInterconnect)
-> Lens
     CreateInterconnect
     CreateInterconnect
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInterconnect' {Maybe (NonEmpty Tag)
tags :: Maybe (NonEmpty Tag)
$sel:tags:CreateInterconnect' :: CreateInterconnect -> Maybe (NonEmpty Tag)
tags} -> Maybe (NonEmpty Tag)
tags) (\s :: CreateInterconnect
s@CreateInterconnect' {} Maybe (NonEmpty Tag)
a -> CreateInterconnect
s {$sel:tags:CreateInterconnect' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
a} :: CreateInterconnect) ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
 -> CreateInterconnect -> f CreateInterconnect)
-> ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
    -> Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> CreateInterconnect
-> f CreateInterconnect
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 name of the interconnect.
createInterconnect_interconnectName :: Lens.Lens' CreateInterconnect Prelude.Text
createInterconnect_interconnectName :: (Text -> f Text) -> CreateInterconnect -> f CreateInterconnect
createInterconnect_interconnectName = (CreateInterconnect -> Text)
-> (CreateInterconnect -> Text -> CreateInterconnect)
-> Lens CreateInterconnect CreateInterconnect Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInterconnect' {Text
interconnectName :: Text
$sel:interconnectName:CreateInterconnect' :: CreateInterconnect -> Text
interconnectName} -> Text
interconnectName) (\s :: CreateInterconnect
s@CreateInterconnect' {} Text
a -> CreateInterconnect
s {$sel:interconnectName:CreateInterconnect' :: Text
interconnectName = Text
a} :: CreateInterconnect)

-- | The port bandwidth, in Gbps. The possible values are 1 and 10.
createInterconnect_bandwidth :: Lens.Lens' CreateInterconnect Prelude.Text
createInterconnect_bandwidth :: (Text -> f Text) -> CreateInterconnect -> f CreateInterconnect
createInterconnect_bandwidth = (CreateInterconnect -> Text)
-> (CreateInterconnect -> Text -> CreateInterconnect)
-> Lens CreateInterconnect CreateInterconnect Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInterconnect' {Text
bandwidth :: Text
$sel:bandwidth:CreateInterconnect' :: CreateInterconnect -> Text
bandwidth} -> Text
bandwidth) (\s :: CreateInterconnect
s@CreateInterconnect' {} Text
a -> CreateInterconnect
s {$sel:bandwidth:CreateInterconnect' :: Text
bandwidth = Text
a} :: CreateInterconnect)

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

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

instance Prelude.Hashable CreateInterconnect

instance Prelude.NFData CreateInterconnect

instance Core.ToHeaders CreateInterconnect where
  toHeaders :: CreateInterconnect -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateInterconnect -> 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.CreateInterconnect" ::
                          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 CreateInterconnect where
  toJSON :: CreateInterconnect -> Value
toJSON CreateInterconnect' {Maybe (NonEmpty Tag)
Maybe Text
Text
location :: Text
bandwidth :: Text
interconnectName :: Text
tags :: Maybe (NonEmpty Tag)
providerName :: Maybe Text
lagId :: Maybe Text
$sel:location:CreateInterconnect' :: CreateInterconnect -> Text
$sel:bandwidth:CreateInterconnect' :: CreateInterconnect -> Text
$sel:interconnectName:CreateInterconnect' :: CreateInterconnect -> Text
$sel:tags:CreateInterconnect' :: CreateInterconnect -> Maybe (NonEmpty Tag)
$sel:providerName:CreateInterconnect' :: CreateInterconnect -> Maybe Text
$sel:lagId:CreateInterconnect' :: CreateInterconnect -> 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
"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
"interconnectName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
interconnectName),
            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
"location" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
location)
          ]
      )

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

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