{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.EKS.Types.RemoteAccessConfig
-- 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)
module Amazonka.EKS.Types.RemoteAccessConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object representing the remote access configuration for the managed
-- node group.
--
-- /See:/ 'newRemoteAccessConfig' smart constructor.
data RemoteAccessConfig = RemoteAccessConfig'
  { -- | The security groups that are allowed SSH access (port 22) to the nodes.
    -- If you specify an Amazon EC2 SSH key but do not specify a source
    -- security group when you create a managed node group, then port 22 on the
    -- nodes is opened to the internet (0.0.0.0\/0). For more information, see
    -- <https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html Security Groups for Your VPC>
    -- in the /Amazon Virtual Private Cloud User Guide/.
    RemoteAccessConfig -> Maybe [Text]
sourceSecurityGroups :: Prelude.Maybe [Prelude.Text],
    -- | The Amazon EC2 SSH key that provides access for SSH communication with
    -- the nodes in the managed node group. For more information, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html Amazon EC2 key pairs and Linux instances>
    -- in the /Amazon Elastic Compute Cloud User Guide for Linux Instances/.
    RemoteAccessConfig -> Maybe Text
ec2SshKey :: Prelude.Maybe Prelude.Text
  }
  deriving (RemoteAccessConfig -> RemoteAccessConfig -> Bool
(RemoteAccessConfig -> RemoteAccessConfig -> Bool)
-> (RemoteAccessConfig -> RemoteAccessConfig -> Bool)
-> Eq RemoteAccessConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RemoteAccessConfig -> RemoteAccessConfig -> Bool
$c/= :: RemoteAccessConfig -> RemoteAccessConfig -> Bool
== :: RemoteAccessConfig -> RemoteAccessConfig -> Bool
$c== :: RemoteAccessConfig -> RemoteAccessConfig -> Bool
Prelude.Eq, ReadPrec [RemoteAccessConfig]
ReadPrec RemoteAccessConfig
Int -> ReadS RemoteAccessConfig
ReadS [RemoteAccessConfig]
(Int -> ReadS RemoteAccessConfig)
-> ReadS [RemoteAccessConfig]
-> ReadPrec RemoteAccessConfig
-> ReadPrec [RemoteAccessConfig]
-> Read RemoteAccessConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RemoteAccessConfig]
$creadListPrec :: ReadPrec [RemoteAccessConfig]
readPrec :: ReadPrec RemoteAccessConfig
$creadPrec :: ReadPrec RemoteAccessConfig
readList :: ReadS [RemoteAccessConfig]
$creadList :: ReadS [RemoteAccessConfig]
readsPrec :: Int -> ReadS RemoteAccessConfig
$creadsPrec :: Int -> ReadS RemoteAccessConfig
Prelude.Read, Int -> RemoteAccessConfig -> ShowS
[RemoteAccessConfig] -> ShowS
RemoteAccessConfig -> String
(Int -> RemoteAccessConfig -> ShowS)
-> (RemoteAccessConfig -> String)
-> ([RemoteAccessConfig] -> ShowS)
-> Show RemoteAccessConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RemoteAccessConfig] -> ShowS
$cshowList :: [RemoteAccessConfig] -> ShowS
show :: RemoteAccessConfig -> String
$cshow :: RemoteAccessConfig -> String
showsPrec :: Int -> RemoteAccessConfig -> ShowS
$cshowsPrec :: Int -> RemoteAccessConfig -> ShowS
Prelude.Show, (forall x. RemoteAccessConfig -> Rep RemoteAccessConfig x)
-> (forall x. Rep RemoteAccessConfig x -> RemoteAccessConfig)
-> Generic RemoteAccessConfig
forall x. Rep RemoteAccessConfig x -> RemoteAccessConfig
forall x. RemoteAccessConfig -> Rep RemoteAccessConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RemoteAccessConfig x -> RemoteAccessConfig
$cfrom :: forall x. RemoteAccessConfig -> Rep RemoteAccessConfig x
Prelude.Generic)

-- |
-- Create a value of 'RemoteAccessConfig' 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:
--
-- 'sourceSecurityGroups', 'remoteAccessConfig_sourceSecurityGroups' - The security groups that are allowed SSH access (port 22) to the nodes.
-- If you specify an Amazon EC2 SSH key but do not specify a source
-- security group when you create a managed node group, then port 22 on the
-- nodes is opened to the internet (0.0.0.0\/0). For more information, see
-- <https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html Security Groups for Your VPC>
-- in the /Amazon Virtual Private Cloud User Guide/.
--
-- 'ec2SshKey', 'remoteAccessConfig_ec2SshKey' - The Amazon EC2 SSH key that provides access for SSH communication with
-- the nodes in the managed node group. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html Amazon EC2 key pairs and Linux instances>
-- in the /Amazon Elastic Compute Cloud User Guide for Linux Instances/.
newRemoteAccessConfig ::
  RemoteAccessConfig
newRemoteAccessConfig :: RemoteAccessConfig
newRemoteAccessConfig =
  RemoteAccessConfig' :: Maybe [Text] -> Maybe Text -> RemoteAccessConfig
RemoteAccessConfig'
    { $sel:sourceSecurityGroups:RemoteAccessConfig' :: Maybe [Text]
sourceSecurityGroups =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:ec2SshKey:RemoteAccessConfig' :: Maybe Text
ec2SshKey = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The security groups that are allowed SSH access (port 22) to the nodes.
-- If you specify an Amazon EC2 SSH key but do not specify a source
-- security group when you create a managed node group, then port 22 on the
-- nodes is opened to the internet (0.0.0.0\/0). For more information, see
-- <https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html Security Groups for Your VPC>
-- in the /Amazon Virtual Private Cloud User Guide/.
remoteAccessConfig_sourceSecurityGroups :: Lens.Lens' RemoteAccessConfig (Prelude.Maybe [Prelude.Text])
remoteAccessConfig_sourceSecurityGroups :: (Maybe [Text] -> f (Maybe [Text]))
-> RemoteAccessConfig -> f RemoteAccessConfig
remoteAccessConfig_sourceSecurityGroups = (RemoteAccessConfig -> Maybe [Text])
-> (RemoteAccessConfig -> Maybe [Text] -> RemoteAccessConfig)
-> Lens
     RemoteAccessConfig RemoteAccessConfig (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RemoteAccessConfig' {Maybe [Text]
sourceSecurityGroups :: Maybe [Text]
$sel:sourceSecurityGroups:RemoteAccessConfig' :: RemoteAccessConfig -> Maybe [Text]
sourceSecurityGroups} -> Maybe [Text]
sourceSecurityGroups) (\s :: RemoteAccessConfig
s@RemoteAccessConfig' {} Maybe [Text]
a -> RemoteAccessConfig
s {$sel:sourceSecurityGroups:RemoteAccessConfig' :: Maybe [Text]
sourceSecurityGroups = Maybe [Text]
a} :: RemoteAccessConfig) ((Maybe [Text] -> f (Maybe [Text]))
 -> RemoteAccessConfig -> f RemoteAccessConfig)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> RemoteAccessConfig
-> f RemoteAccessConfig
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 EC2 SSH key that provides access for SSH communication with
-- the nodes in the managed node group. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html Amazon EC2 key pairs and Linux instances>
-- in the /Amazon Elastic Compute Cloud User Guide for Linux Instances/.
remoteAccessConfig_ec2SshKey :: Lens.Lens' RemoteAccessConfig (Prelude.Maybe Prelude.Text)
remoteAccessConfig_ec2SshKey :: (Maybe Text -> f (Maybe Text))
-> RemoteAccessConfig -> f RemoteAccessConfig
remoteAccessConfig_ec2SshKey = (RemoteAccessConfig -> Maybe Text)
-> (RemoteAccessConfig -> Maybe Text -> RemoteAccessConfig)
-> Lens
     RemoteAccessConfig RemoteAccessConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RemoteAccessConfig' {Maybe Text
ec2SshKey :: Maybe Text
$sel:ec2SshKey:RemoteAccessConfig' :: RemoteAccessConfig -> Maybe Text
ec2SshKey} -> Maybe Text
ec2SshKey) (\s :: RemoteAccessConfig
s@RemoteAccessConfig' {} Maybe Text
a -> RemoteAccessConfig
s {$sel:ec2SshKey:RemoteAccessConfig' :: Maybe Text
ec2SshKey = Maybe Text
a} :: RemoteAccessConfig)

instance Core.FromJSON RemoteAccessConfig where
  parseJSON :: Value -> Parser RemoteAccessConfig
parseJSON =
    String
-> (Object -> Parser RemoteAccessConfig)
-> Value
-> Parser RemoteAccessConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RemoteAccessConfig"
      ( \Object
x ->
          Maybe [Text] -> Maybe Text -> RemoteAccessConfig
RemoteAccessConfig'
            (Maybe [Text] -> Maybe Text -> RemoteAccessConfig)
-> Parser (Maybe [Text])
-> Parser (Maybe Text -> RemoteAccessConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"sourceSecurityGroups"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Text -> RemoteAccessConfig)
-> Parser (Maybe Text) -> Parser RemoteAccessConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ec2SshKey")
      )

instance Prelude.Hashable RemoteAccessConfig

instance Prelude.NFData RemoteAccessConfig

instance Core.ToJSON RemoteAccessConfig where
  toJSON :: RemoteAccessConfig -> Value
toJSON RemoteAccessConfig' {Maybe [Text]
Maybe Text
ec2SshKey :: Maybe Text
sourceSecurityGroups :: Maybe [Text]
$sel:ec2SshKey:RemoteAccessConfig' :: RemoteAccessConfig -> Maybe Text
$sel:sourceSecurityGroups:RemoteAccessConfig' :: RemoteAccessConfig -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"sourceSecurityGroups" 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]
sourceSecurityGroups,
            (Text
"ec2SshKey" 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
ec2SshKey
          ]
      )