{-# 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.Redshift.CreateEndpointAccess
-- 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 Redshift-managed VPC endpoint.
module Amazonka.Redshift.CreateEndpointAccess
  ( -- * Creating a Request
    CreateEndpointAccess (..),
    newCreateEndpointAccess,

    -- * Request Lenses
    createEndpointAccess_clusterIdentifier,
    createEndpointAccess_vpcSecurityGroupIds,
    createEndpointAccess_resourceOwner,
    createEndpointAccess_endpointName,
    createEndpointAccess_subnetGroupName,

    -- * Destructuring the Response
    EndpointAccess (..),
    newEndpointAccess,

    -- * Response Lenses
    endpointAccess_endpointName,
    endpointAccess_endpointCreateTime,
    endpointAccess_subnetGroupName,
    endpointAccess_address,
    endpointAccess_clusterIdentifier,
    endpointAccess_endpointStatus,
    endpointAccess_vpcSecurityGroups,
    endpointAccess_resourceOwner,
    endpointAccess_vpcEndpoint,
    endpointAccess_port,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Redshift.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateEndpointAccess' smart constructor.
data CreateEndpointAccess = CreateEndpointAccess'
  { -- | The cluster identifier of the cluster to access.
    CreateEndpointAccess -> Maybe Text
clusterIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The security group that defines the ports, protocols, and sources for
    -- inbound traffic that you are authorizing into your endpoint.
    CreateEndpointAccess -> Maybe [Text]
vpcSecurityGroupIds :: Prelude.Maybe [Prelude.Text],
    -- | The Amazon Web Services account ID of the owner of the cluster. This is
    -- only required if the cluster is in another Amazon Web Services account.
    CreateEndpointAccess -> Maybe Text
resourceOwner :: Prelude.Maybe Prelude.Text,
    -- | The Redshift-managed VPC endpoint name.
    --
    -- An endpoint name must contain 1-30 characters. Valid characters are A-Z,
    -- a-z, 0-9, and hyphen(-). The first character must be a letter. The name
    -- can\'t contain two consecutive hyphens or end with a hyphen.
    CreateEndpointAccess -> Text
endpointName :: Prelude.Text,
    -- | The subnet group from which Amazon Redshift chooses the subnet to deploy
    -- the endpoint.
    CreateEndpointAccess -> Text
subnetGroupName :: Prelude.Text
  }
  deriving (CreateEndpointAccess -> CreateEndpointAccess -> Bool
(CreateEndpointAccess -> CreateEndpointAccess -> Bool)
-> (CreateEndpointAccess -> CreateEndpointAccess -> Bool)
-> Eq CreateEndpointAccess
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateEndpointAccess -> CreateEndpointAccess -> Bool
$c/= :: CreateEndpointAccess -> CreateEndpointAccess -> Bool
== :: CreateEndpointAccess -> CreateEndpointAccess -> Bool
$c== :: CreateEndpointAccess -> CreateEndpointAccess -> Bool
Prelude.Eq, ReadPrec [CreateEndpointAccess]
ReadPrec CreateEndpointAccess
Int -> ReadS CreateEndpointAccess
ReadS [CreateEndpointAccess]
(Int -> ReadS CreateEndpointAccess)
-> ReadS [CreateEndpointAccess]
-> ReadPrec CreateEndpointAccess
-> ReadPrec [CreateEndpointAccess]
-> Read CreateEndpointAccess
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateEndpointAccess]
$creadListPrec :: ReadPrec [CreateEndpointAccess]
readPrec :: ReadPrec CreateEndpointAccess
$creadPrec :: ReadPrec CreateEndpointAccess
readList :: ReadS [CreateEndpointAccess]
$creadList :: ReadS [CreateEndpointAccess]
readsPrec :: Int -> ReadS CreateEndpointAccess
$creadsPrec :: Int -> ReadS CreateEndpointAccess
Prelude.Read, Int -> CreateEndpointAccess -> ShowS
[CreateEndpointAccess] -> ShowS
CreateEndpointAccess -> String
(Int -> CreateEndpointAccess -> ShowS)
-> (CreateEndpointAccess -> String)
-> ([CreateEndpointAccess] -> ShowS)
-> Show CreateEndpointAccess
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateEndpointAccess] -> ShowS
$cshowList :: [CreateEndpointAccess] -> ShowS
show :: CreateEndpointAccess -> String
$cshow :: CreateEndpointAccess -> String
showsPrec :: Int -> CreateEndpointAccess -> ShowS
$cshowsPrec :: Int -> CreateEndpointAccess -> ShowS
Prelude.Show, (forall x. CreateEndpointAccess -> Rep CreateEndpointAccess x)
-> (forall x. Rep CreateEndpointAccess x -> CreateEndpointAccess)
-> Generic CreateEndpointAccess
forall x. Rep CreateEndpointAccess x -> CreateEndpointAccess
forall x. CreateEndpointAccess -> Rep CreateEndpointAccess x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateEndpointAccess x -> CreateEndpointAccess
$cfrom :: forall x. CreateEndpointAccess -> Rep CreateEndpointAccess x
Prelude.Generic)

-- |
-- Create a value of 'CreateEndpointAccess' 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:
--
-- 'clusterIdentifier', 'createEndpointAccess_clusterIdentifier' - The cluster identifier of the cluster to access.
--
-- 'vpcSecurityGroupIds', 'createEndpointAccess_vpcSecurityGroupIds' - The security group that defines the ports, protocols, and sources for
-- inbound traffic that you are authorizing into your endpoint.
--
-- 'resourceOwner', 'createEndpointAccess_resourceOwner' - The Amazon Web Services account ID of the owner of the cluster. This is
-- only required if the cluster is in another Amazon Web Services account.
--
-- 'endpointName', 'createEndpointAccess_endpointName' - The Redshift-managed VPC endpoint name.
--
-- An endpoint name must contain 1-30 characters. Valid characters are A-Z,
-- a-z, 0-9, and hyphen(-). The first character must be a letter. The name
-- can\'t contain two consecutive hyphens or end with a hyphen.
--
-- 'subnetGroupName', 'createEndpointAccess_subnetGroupName' - The subnet group from which Amazon Redshift chooses the subnet to deploy
-- the endpoint.
newCreateEndpointAccess ::
  -- | 'endpointName'
  Prelude.Text ->
  -- | 'subnetGroupName'
  Prelude.Text ->
  CreateEndpointAccess
newCreateEndpointAccess :: Text -> Text -> CreateEndpointAccess
newCreateEndpointAccess
  Text
pEndpointName_
  Text
pSubnetGroupName_ =
    CreateEndpointAccess' :: Maybe Text
-> Maybe [Text]
-> Maybe Text
-> Text
-> Text
-> CreateEndpointAccess
CreateEndpointAccess'
      { $sel:clusterIdentifier:CreateEndpointAccess' :: Maybe Text
clusterIdentifier =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:vpcSecurityGroupIds:CreateEndpointAccess' :: Maybe [Text]
vpcSecurityGroupIds = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
        $sel:resourceOwner:CreateEndpointAccess' :: Maybe Text
resourceOwner = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:endpointName:CreateEndpointAccess' :: Text
endpointName = Text
pEndpointName_,
        $sel:subnetGroupName:CreateEndpointAccess' :: Text
subnetGroupName = Text
pSubnetGroupName_
      }

-- | The cluster identifier of the cluster to access.
createEndpointAccess_clusterIdentifier :: Lens.Lens' CreateEndpointAccess (Prelude.Maybe Prelude.Text)
createEndpointAccess_clusterIdentifier :: (Maybe Text -> f (Maybe Text))
-> CreateEndpointAccess -> f CreateEndpointAccess
createEndpointAccess_clusterIdentifier = (CreateEndpointAccess -> Maybe Text)
-> (CreateEndpointAccess -> Maybe Text -> CreateEndpointAccess)
-> Lens
     CreateEndpointAccess CreateEndpointAccess (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEndpointAccess' {Maybe Text
clusterIdentifier :: Maybe Text
$sel:clusterIdentifier:CreateEndpointAccess' :: CreateEndpointAccess -> Maybe Text
clusterIdentifier} -> Maybe Text
clusterIdentifier) (\s :: CreateEndpointAccess
s@CreateEndpointAccess' {} Maybe Text
a -> CreateEndpointAccess
s {$sel:clusterIdentifier:CreateEndpointAccess' :: Maybe Text
clusterIdentifier = Maybe Text
a} :: CreateEndpointAccess)

-- | The security group that defines the ports, protocols, and sources for
-- inbound traffic that you are authorizing into your endpoint.
createEndpointAccess_vpcSecurityGroupIds :: Lens.Lens' CreateEndpointAccess (Prelude.Maybe [Prelude.Text])
createEndpointAccess_vpcSecurityGroupIds :: (Maybe [Text] -> f (Maybe [Text]))
-> CreateEndpointAccess -> f CreateEndpointAccess
createEndpointAccess_vpcSecurityGroupIds = (CreateEndpointAccess -> Maybe [Text])
-> (CreateEndpointAccess -> Maybe [Text] -> CreateEndpointAccess)
-> Lens
     CreateEndpointAccess
     CreateEndpointAccess
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEndpointAccess' {Maybe [Text]
vpcSecurityGroupIds :: Maybe [Text]
$sel:vpcSecurityGroupIds:CreateEndpointAccess' :: CreateEndpointAccess -> Maybe [Text]
vpcSecurityGroupIds} -> Maybe [Text]
vpcSecurityGroupIds) (\s :: CreateEndpointAccess
s@CreateEndpointAccess' {} Maybe [Text]
a -> CreateEndpointAccess
s {$sel:vpcSecurityGroupIds:CreateEndpointAccess' :: Maybe [Text]
vpcSecurityGroupIds = Maybe [Text]
a} :: CreateEndpointAccess) ((Maybe [Text] -> f (Maybe [Text]))
 -> CreateEndpointAccess -> f CreateEndpointAccess)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> CreateEndpointAccess
-> f CreateEndpointAccess
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Web Services account ID of the owner of the cluster. This is
-- only required if the cluster is in another Amazon Web Services account.
createEndpointAccess_resourceOwner :: Lens.Lens' CreateEndpointAccess (Prelude.Maybe Prelude.Text)
createEndpointAccess_resourceOwner :: (Maybe Text -> f (Maybe Text))
-> CreateEndpointAccess -> f CreateEndpointAccess
createEndpointAccess_resourceOwner = (CreateEndpointAccess -> Maybe Text)
-> (CreateEndpointAccess -> Maybe Text -> CreateEndpointAccess)
-> Lens
     CreateEndpointAccess CreateEndpointAccess (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEndpointAccess' {Maybe Text
resourceOwner :: Maybe Text
$sel:resourceOwner:CreateEndpointAccess' :: CreateEndpointAccess -> Maybe Text
resourceOwner} -> Maybe Text
resourceOwner) (\s :: CreateEndpointAccess
s@CreateEndpointAccess' {} Maybe Text
a -> CreateEndpointAccess
s {$sel:resourceOwner:CreateEndpointAccess' :: Maybe Text
resourceOwner = Maybe Text
a} :: CreateEndpointAccess)

-- | The Redshift-managed VPC endpoint name.
--
-- An endpoint name must contain 1-30 characters. Valid characters are A-Z,
-- a-z, 0-9, and hyphen(-). The first character must be a letter. The name
-- can\'t contain two consecutive hyphens or end with a hyphen.
createEndpointAccess_endpointName :: Lens.Lens' CreateEndpointAccess Prelude.Text
createEndpointAccess_endpointName :: (Text -> f Text) -> CreateEndpointAccess -> f CreateEndpointAccess
createEndpointAccess_endpointName = (CreateEndpointAccess -> Text)
-> (CreateEndpointAccess -> Text -> CreateEndpointAccess)
-> Lens CreateEndpointAccess CreateEndpointAccess Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEndpointAccess' {Text
endpointName :: Text
$sel:endpointName:CreateEndpointAccess' :: CreateEndpointAccess -> Text
endpointName} -> Text
endpointName) (\s :: CreateEndpointAccess
s@CreateEndpointAccess' {} Text
a -> CreateEndpointAccess
s {$sel:endpointName:CreateEndpointAccess' :: Text
endpointName = Text
a} :: CreateEndpointAccess)

-- | The subnet group from which Amazon Redshift chooses the subnet to deploy
-- the endpoint.
createEndpointAccess_subnetGroupName :: Lens.Lens' CreateEndpointAccess Prelude.Text
createEndpointAccess_subnetGroupName :: (Text -> f Text) -> CreateEndpointAccess -> f CreateEndpointAccess
createEndpointAccess_subnetGroupName = (CreateEndpointAccess -> Text)
-> (CreateEndpointAccess -> Text -> CreateEndpointAccess)
-> Lens CreateEndpointAccess CreateEndpointAccess Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEndpointAccess' {Text
subnetGroupName :: Text
$sel:subnetGroupName:CreateEndpointAccess' :: CreateEndpointAccess -> Text
subnetGroupName} -> Text
subnetGroupName) (\s :: CreateEndpointAccess
s@CreateEndpointAccess' {} Text
a -> CreateEndpointAccess
s {$sel:subnetGroupName:CreateEndpointAccess' :: Text
subnetGroupName = Text
a} :: CreateEndpointAccess)

instance Core.AWSRequest CreateEndpointAccess where
  type
    AWSResponse CreateEndpointAccess =
      EndpointAccess
  request :: CreateEndpointAccess -> Request CreateEndpointAccess
request = Service -> CreateEndpointAccess -> Request CreateEndpointAccess
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateEndpointAccess
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateEndpointAccess)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse CreateEndpointAccess))
-> Logger
-> Service
-> Proxy CreateEndpointAccess
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateEndpointAccess)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"CreateEndpointAccessResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String EndpointAccess
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable CreateEndpointAccess

instance Prelude.NFData CreateEndpointAccess

instance Core.ToHeaders CreateEndpointAccess where
  toHeaders :: CreateEndpointAccess -> ResponseHeaders
toHeaders = ResponseHeaders -> CreateEndpointAccess -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery CreateEndpointAccess where
  toQuery :: CreateEndpointAccess -> QueryString
toQuery CreateEndpointAccess' {Maybe [Text]
Maybe Text
Text
subnetGroupName :: Text
endpointName :: Text
resourceOwner :: Maybe Text
vpcSecurityGroupIds :: Maybe [Text]
clusterIdentifier :: Maybe Text
$sel:subnetGroupName:CreateEndpointAccess' :: CreateEndpointAccess -> Text
$sel:endpointName:CreateEndpointAccess' :: CreateEndpointAccess -> Text
$sel:resourceOwner:CreateEndpointAccess' :: CreateEndpointAccess -> Maybe Text
$sel:vpcSecurityGroupIds:CreateEndpointAccess' :: CreateEndpointAccess -> Maybe [Text]
$sel:clusterIdentifier:CreateEndpointAccess' :: CreateEndpointAccess -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"CreateEndpointAccess" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2012-12-01" :: Prelude.ByteString),
        ByteString
"ClusterIdentifier" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
clusterIdentifier,
        ByteString
"VpcSecurityGroupIds"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            ( ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"VpcSecurityGroupId"
                ([Text] -> QueryString) -> Maybe [Text] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
vpcSecurityGroupIds
            ),
        ByteString
"ResourceOwner" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
resourceOwner,
        ByteString
"EndpointName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
endpointName,
        ByteString
"SubnetGroupName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
subnetGroupName
      ]