{-# 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.MwAA.Types.NetworkConfiguration
-- 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.MwAA.Types.NetworkConfiguration where

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

-- | The VPC networking components used to secure and enable network traffic
-- between the AWS resources for your environment. To learn more, see
-- <https://docs.aws.amazon.com/mwaa/latest/userguide/networking-about.html About networking on Amazon MWAA>.
--
-- /See:/ 'newNetworkConfiguration' smart constructor.
data NetworkConfiguration = NetworkConfiguration'
  { -- | A list of 1 or more security group IDs. Accepts up to 5 security group
    -- IDs. A security group must be attached to the same VPC as the subnets.
    -- To learn more, see
    -- <https://docs.aws.amazon.com/mwaa/latest/userguide/vpc-security.html Security in your VPC on Amazon MWAA>.
    NetworkConfiguration -> Maybe (NonEmpty Text)
securityGroupIds :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | A list of 2 subnet IDs. __Required__ to create an environment. Must be
    -- private subnets in two different availability zones. A subnet must be
    -- attached to the same VPC as the security group.
    NetworkConfiguration -> Maybe (NonEmpty Text)
subnetIds :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (NetworkConfiguration -> NetworkConfiguration -> Bool
(NetworkConfiguration -> NetworkConfiguration -> Bool)
-> (NetworkConfiguration -> NetworkConfiguration -> Bool)
-> Eq NetworkConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetworkConfiguration -> NetworkConfiguration -> Bool
$c/= :: NetworkConfiguration -> NetworkConfiguration -> Bool
== :: NetworkConfiguration -> NetworkConfiguration -> Bool
$c== :: NetworkConfiguration -> NetworkConfiguration -> Bool
Prelude.Eq, ReadPrec [NetworkConfiguration]
ReadPrec NetworkConfiguration
Int -> ReadS NetworkConfiguration
ReadS [NetworkConfiguration]
(Int -> ReadS NetworkConfiguration)
-> ReadS [NetworkConfiguration]
-> ReadPrec NetworkConfiguration
-> ReadPrec [NetworkConfiguration]
-> Read NetworkConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NetworkConfiguration]
$creadListPrec :: ReadPrec [NetworkConfiguration]
readPrec :: ReadPrec NetworkConfiguration
$creadPrec :: ReadPrec NetworkConfiguration
readList :: ReadS [NetworkConfiguration]
$creadList :: ReadS [NetworkConfiguration]
readsPrec :: Int -> ReadS NetworkConfiguration
$creadsPrec :: Int -> ReadS NetworkConfiguration
Prelude.Read, Int -> NetworkConfiguration -> ShowS
[NetworkConfiguration] -> ShowS
NetworkConfiguration -> String
(Int -> NetworkConfiguration -> ShowS)
-> (NetworkConfiguration -> String)
-> ([NetworkConfiguration] -> ShowS)
-> Show NetworkConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetworkConfiguration] -> ShowS
$cshowList :: [NetworkConfiguration] -> ShowS
show :: NetworkConfiguration -> String
$cshow :: NetworkConfiguration -> String
showsPrec :: Int -> NetworkConfiguration -> ShowS
$cshowsPrec :: Int -> NetworkConfiguration -> ShowS
Prelude.Show, (forall x. NetworkConfiguration -> Rep NetworkConfiguration x)
-> (forall x. Rep NetworkConfiguration x -> NetworkConfiguration)
-> Generic NetworkConfiguration
forall x. Rep NetworkConfiguration x -> NetworkConfiguration
forall x. NetworkConfiguration -> Rep NetworkConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NetworkConfiguration x -> NetworkConfiguration
$cfrom :: forall x. NetworkConfiguration -> Rep NetworkConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'NetworkConfiguration' 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:
--
-- 'securityGroupIds', 'networkConfiguration_securityGroupIds' - A list of 1 or more security group IDs. Accepts up to 5 security group
-- IDs. A security group must be attached to the same VPC as the subnets.
-- To learn more, see
-- <https://docs.aws.amazon.com/mwaa/latest/userguide/vpc-security.html Security in your VPC on Amazon MWAA>.
--
-- 'subnetIds', 'networkConfiguration_subnetIds' - A list of 2 subnet IDs. __Required__ to create an environment. Must be
-- private subnets in two different availability zones. A subnet must be
-- attached to the same VPC as the security group.
newNetworkConfiguration ::
  NetworkConfiguration
newNetworkConfiguration :: NetworkConfiguration
newNetworkConfiguration =
  NetworkConfiguration' :: Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text) -> NetworkConfiguration
NetworkConfiguration'
    { $sel:securityGroupIds:NetworkConfiguration' :: Maybe (NonEmpty Text)
securityGroupIds =
        Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:subnetIds:NetworkConfiguration' :: Maybe (NonEmpty Text)
subnetIds = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | A list of 1 or more security group IDs. Accepts up to 5 security group
-- IDs. A security group must be attached to the same VPC as the subnets.
-- To learn more, see
-- <https://docs.aws.amazon.com/mwaa/latest/userguide/vpc-security.html Security in your VPC on Amazon MWAA>.
networkConfiguration_securityGroupIds :: Lens.Lens' NetworkConfiguration (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
networkConfiguration_securityGroupIds :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> NetworkConfiguration -> f NetworkConfiguration
networkConfiguration_securityGroupIds = (NetworkConfiguration -> Maybe (NonEmpty Text))
-> (NetworkConfiguration
    -> Maybe (NonEmpty Text) -> NetworkConfiguration)
-> Lens
     NetworkConfiguration
     NetworkConfiguration
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkConfiguration' {Maybe (NonEmpty Text)
securityGroupIds :: Maybe (NonEmpty Text)
$sel:securityGroupIds:NetworkConfiguration' :: NetworkConfiguration -> Maybe (NonEmpty Text)
securityGroupIds} -> Maybe (NonEmpty Text)
securityGroupIds) (\s :: NetworkConfiguration
s@NetworkConfiguration' {} Maybe (NonEmpty Text)
a -> NetworkConfiguration
s {$sel:securityGroupIds:NetworkConfiguration' :: Maybe (NonEmpty Text)
securityGroupIds = Maybe (NonEmpty Text)
a} :: NetworkConfiguration) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> NetworkConfiguration -> f NetworkConfiguration)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> NetworkConfiguration
-> f NetworkConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty 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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of 2 subnet IDs. __Required__ to create an environment. Must be
-- private subnets in two different availability zones. A subnet must be
-- attached to the same VPC as the security group.
networkConfiguration_subnetIds :: Lens.Lens' NetworkConfiguration (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
networkConfiguration_subnetIds :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> NetworkConfiguration -> f NetworkConfiguration
networkConfiguration_subnetIds = (NetworkConfiguration -> Maybe (NonEmpty Text))
-> (NetworkConfiguration
    -> Maybe (NonEmpty Text) -> NetworkConfiguration)
-> Lens
     NetworkConfiguration
     NetworkConfiguration
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkConfiguration' {Maybe (NonEmpty Text)
subnetIds :: Maybe (NonEmpty Text)
$sel:subnetIds:NetworkConfiguration' :: NetworkConfiguration -> Maybe (NonEmpty Text)
subnetIds} -> Maybe (NonEmpty Text)
subnetIds) (\s :: NetworkConfiguration
s@NetworkConfiguration' {} Maybe (NonEmpty Text)
a -> NetworkConfiguration
s {$sel:subnetIds:NetworkConfiguration' :: Maybe (NonEmpty Text)
subnetIds = Maybe (NonEmpty Text)
a} :: NetworkConfiguration) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> NetworkConfiguration -> f NetworkConfiguration)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> NetworkConfiguration
-> f NetworkConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty 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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON NetworkConfiguration where
  parseJSON :: Value -> Parser NetworkConfiguration
parseJSON =
    String
-> (Object -> Parser NetworkConfiguration)
-> Value
-> Parser NetworkConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NetworkConfiguration"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text) -> NetworkConfiguration
NetworkConfiguration'
            (Maybe (NonEmpty Text)
 -> Maybe (NonEmpty Text) -> NetworkConfiguration)
-> Parser (Maybe (NonEmpty Text))
-> Parser (Maybe (NonEmpty Text) -> NetworkConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SecurityGroupIds")
            Parser (Maybe (NonEmpty Text) -> NetworkConfiguration)
-> Parser (Maybe (NonEmpty Text)) -> Parser NetworkConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SubnetIds")
      )

instance Prelude.Hashable NetworkConfiguration

instance Prelude.NFData NetworkConfiguration

instance Core.ToJSON NetworkConfiguration where
  toJSON :: NetworkConfiguration -> Value
toJSON NetworkConfiguration' {Maybe (NonEmpty Text)
subnetIds :: Maybe (NonEmpty Text)
securityGroupIds :: Maybe (NonEmpty Text)
$sel:subnetIds:NetworkConfiguration' :: NetworkConfiguration -> Maybe (NonEmpty Text)
$sel:securityGroupIds:NetworkConfiguration' :: NetworkConfiguration -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SecurityGroupIds" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
securityGroupIds,
            (Text
"SubnetIds" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
subnetIds
          ]
      )