{-# 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.AppRunner.Types.EgressConfiguration
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AppRunner.Types.EgressConfiguration where

import Amazonka.AppRunner.Types.EgressType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Describes configuration settings related to outbound network traffic of
-- an App Runner service.
--
-- /See:/ 'newEgressConfiguration' smart constructor.
data EgressConfiguration = EgressConfiguration'
  { -- | The type of egress configuration.
    --
    -- Set to @DEFAULT@ for access to resources hosted on public networks.
    --
    -- Set to @VPC@ to associate your service to a custom VPC specified by
    -- @VpcConnectorArn@.
    EgressConfiguration -> Maybe EgressType
egressType :: Prelude.Maybe EgressType,
    -- | The Amazon Resource Name (ARN) of the App Runner VPC connector that you
    -- want to associate with your App Runner service. Only valid when
    -- @EgressType = VPC@.
    EgressConfiguration -> Maybe Text
vpcConnectorArn :: Prelude.Maybe Prelude.Text
  }
  deriving (EgressConfiguration -> EgressConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EgressConfiguration -> EgressConfiguration -> Bool
$c/= :: EgressConfiguration -> EgressConfiguration -> Bool
== :: EgressConfiguration -> EgressConfiguration -> Bool
$c== :: EgressConfiguration -> EgressConfiguration -> Bool
Prelude.Eq, ReadPrec [EgressConfiguration]
ReadPrec EgressConfiguration
Int -> ReadS EgressConfiguration
ReadS [EgressConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EgressConfiguration]
$creadListPrec :: ReadPrec [EgressConfiguration]
readPrec :: ReadPrec EgressConfiguration
$creadPrec :: ReadPrec EgressConfiguration
readList :: ReadS [EgressConfiguration]
$creadList :: ReadS [EgressConfiguration]
readsPrec :: Int -> ReadS EgressConfiguration
$creadsPrec :: Int -> ReadS EgressConfiguration
Prelude.Read, Int -> EgressConfiguration -> ShowS
[EgressConfiguration] -> ShowS
EgressConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EgressConfiguration] -> ShowS
$cshowList :: [EgressConfiguration] -> ShowS
show :: EgressConfiguration -> String
$cshow :: EgressConfiguration -> String
showsPrec :: Int -> EgressConfiguration -> ShowS
$cshowsPrec :: Int -> EgressConfiguration -> ShowS
Prelude.Show, forall x. Rep EgressConfiguration x -> EgressConfiguration
forall x. EgressConfiguration -> Rep EgressConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EgressConfiguration x -> EgressConfiguration
$cfrom :: forall x. EgressConfiguration -> Rep EgressConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'EgressConfiguration' 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:
--
-- 'egressType', 'egressConfiguration_egressType' - The type of egress configuration.
--
-- Set to @DEFAULT@ for access to resources hosted on public networks.
--
-- Set to @VPC@ to associate your service to a custom VPC specified by
-- @VpcConnectorArn@.
--
-- 'vpcConnectorArn', 'egressConfiguration_vpcConnectorArn' - The Amazon Resource Name (ARN) of the App Runner VPC connector that you
-- want to associate with your App Runner service. Only valid when
-- @EgressType = VPC@.
newEgressConfiguration ::
  EgressConfiguration
newEgressConfiguration :: EgressConfiguration
newEgressConfiguration =
  EgressConfiguration'
    { $sel:egressType:EgressConfiguration' :: Maybe EgressType
egressType = forall a. Maybe a
Prelude.Nothing,
      $sel:vpcConnectorArn:EgressConfiguration' :: Maybe Text
vpcConnectorArn = forall a. Maybe a
Prelude.Nothing
    }

-- | The type of egress configuration.
--
-- Set to @DEFAULT@ for access to resources hosted on public networks.
--
-- Set to @VPC@ to associate your service to a custom VPC specified by
-- @VpcConnectorArn@.
egressConfiguration_egressType :: Lens.Lens' EgressConfiguration (Prelude.Maybe EgressType)
egressConfiguration_egressType :: Lens' EgressConfiguration (Maybe EgressType)
egressConfiguration_egressType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EgressConfiguration' {Maybe EgressType
egressType :: Maybe EgressType
$sel:egressType:EgressConfiguration' :: EgressConfiguration -> Maybe EgressType
egressType} -> Maybe EgressType
egressType) (\s :: EgressConfiguration
s@EgressConfiguration' {} Maybe EgressType
a -> EgressConfiguration
s {$sel:egressType:EgressConfiguration' :: Maybe EgressType
egressType = Maybe EgressType
a} :: EgressConfiguration)

-- | The Amazon Resource Name (ARN) of the App Runner VPC connector that you
-- want to associate with your App Runner service. Only valid when
-- @EgressType = VPC@.
egressConfiguration_vpcConnectorArn :: Lens.Lens' EgressConfiguration (Prelude.Maybe Prelude.Text)
egressConfiguration_vpcConnectorArn :: Lens' EgressConfiguration (Maybe Text)
egressConfiguration_vpcConnectorArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EgressConfiguration' {Maybe Text
vpcConnectorArn :: Maybe Text
$sel:vpcConnectorArn:EgressConfiguration' :: EgressConfiguration -> Maybe Text
vpcConnectorArn} -> Maybe Text
vpcConnectorArn) (\s :: EgressConfiguration
s@EgressConfiguration' {} Maybe Text
a -> EgressConfiguration
s {$sel:vpcConnectorArn:EgressConfiguration' :: Maybe Text
vpcConnectorArn = Maybe Text
a} :: EgressConfiguration)

instance Data.FromJSON EgressConfiguration where
  parseJSON :: Value -> Parser EgressConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EgressConfiguration"
      ( \Object
x ->
          Maybe EgressType -> Maybe Text -> EgressConfiguration
EgressConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"EgressType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"VpcConnectorArn")
      )

instance Prelude.Hashable EgressConfiguration where
  hashWithSalt :: Int -> EgressConfiguration -> Int
hashWithSalt Int
_salt EgressConfiguration' {Maybe Text
Maybe EgressType
vpcConnectorArn :: Maybe Text
egressType :: Maybe EgressType
$sel:vpcConnectorArn:EgressConfiguration' :: EgressConfiguration -> Maybe Text
$sel:egressType:EgressConfiguration' :: EgressConfiguration -> Maybe EgressType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EgressType
egressType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
vpcConnectorArn

instance Prelude.NFData EgressConfiguration where
  rnf :: EgressConfiguration -> ()
rnf EgressConfiguration' {Maybe Text
Maybe EgressType
vpcConnectorArn :: Maybe Text
egressType :: Maybe EgressType
$sel:vpcConnectorArn:EgressConfiguration' :: EgressConfiguration -> Maybe Text
$sel:egressType:EgressConfiguration' :: EgressConfiguration -> Maybe EgressType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EgressType
egressType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
vpcConnectorArn

instance Data.ToJSON EgressConfiguration where
  toJSON :: EgressConfiguration -> Value
toJSON EgressConfiguration' {Maybe Text
Maybe EgressType
vpcConnectorArn :: Maybe Text
egressType :: Maybe EgressType
$sel:vpcConnectorArn:EgressConfiguration' :: EgressConfiguration -> Maybe Text
$sel:egressType:EgressConfiguration' :: EgressConfiguration -> Maybe EgressType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"EgressType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EgressType
egressType,
            (Key
"VpcConnectorArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
vpcConnectorArn
          ]
      )