{-# 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.ECS.Types.ServiceConnectConfiguration
-- 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.ECS.Types.ServiceConnectConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ECS.Types.LogConfiguration
import Amazonka.ECS.Types.ServiceConnectService
import qualified Amazonka.Prelude as Prelude

-- | The Service Connect configuration of your Amazon ECS service. The
-- configuration for this service to discover and connect to services, and
-- be discovered by, and connected from, other services within a namespace.
--
-- Tasks that run in a namespace can use short names to connect to services
-- in the namespace. Tasks can connect to services across all of the
-- clusters in the namespace. Tasks connect through a managed proxy
-- container that collects logs and metrics for increased visibility. Only
-- the tasks that Amazon ECS services create are supported with Service
-- Connect. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html Service Connect>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newServiceConnectConfiguration' smart constructor.
data ServiceConnectConfiguration = ServiceConnectConfiguration'
  { ServiceConnectConfiguration -> Maybe LogConfiguration
logConfiguration :: Prelude.Maybe LogConfiguration,
    -- | The namespace name or full Amazon Resource Name (ARN) of the Cloud Map
    -- namespace for use with Service Connect. The namespace must be in the
    -- same Amazon Web Services Region as the Amazon ECS service and cluster.
    -- The type of namespace doesn\'t affect Service Connect. For more
    -- information about Cloud Map, see
    -- <https://docs.aws.amazon.com/ Working with Services> in the /Cloud Map
    -- Developer Guide/.
    ServiceConnectConfiguration -> Maybe Text
namespace :: Prelude.Maybe Prelude.Text,
    -- | The list of Service Connect service objects. These are names and aliases
    -- (also known as endpoints) that are used by other Amazon ECS services to
    -- connect to this service.
    --
    -- This field is not required for a \"client\" Amazon ECS service that\'s a
    -- member of a namespace only to connect to other services within the
    -- namespace. An example of this would be a frontend application that
    -- accepts incoming requests from either a load balancer that\'s attached
    -- to the service or by other means.
    --
    -- An object selects a port from the task definition, assigns a name for
    -- the Cloud Map service, and a list of aliases (endpoints) and ports for
    -- client applications to refer to this service.
    ServiceConnectConfiguration -> Maybe [ServiceConnectService]
services :: Prelude.Maybe [ServiceConnectService],
    -- | Specifies whether to use Service Connect with this service.
    ServiceConnectConfiguration -> Bool
enabled :: Prelude.Bool
  }
  deriving (ServiceConnectConfiguration -> ServiceConnectConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServiceConnectConfiguration -> ServiceConnectConfiguration -> Bool
$c/= :: ServiceConnectConfiguration -> ServiceConnectConfiguration -> Bool
== :: ServiceConnectConfiguration -> ServiceConnectConfiguration -> Bool
$c== :: ServiceConnectConfiguration -> ServiceConnectConfiguration -> Bool
Prelude.Eq, ReadPrec [ServiceConnectConfiguration]
ReadPrec ServiceConnectConfiguration
Int -> ReadS ServiceConnectConfiguration
ReadS [ServiceConnectConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServiceConnectConfiguration]
$creadListPrec :: ReadPrec [ServiceConnectConfiguration]
readPrec :: ReadPrec ServiceConnectConfiguration
$creadPrec :: ReadPrec ServiceConnectConfiguration
readList :: ReadS [ServiceConnectConfiguration]
$creadList :: ReadS [ServiceConnectConfiguration]
readsPrec :: Int -> ReadS ServiceConnectConfiguration
$creadsPrec :: Int -> ReadS ServiceConnectConfiguration
Prelude.Read, Int -> ServiceConnectConfiguration -> ShowS
[ServiceConnectConfiguration] -> ShowS
ServiceConnectConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServiceConnectConfiguration] -> ShowS
$cshowList :: [ServiceConnectConfiguration] -> ShowS
show :: ServiceConnectConfiguration -> String
$cshow :: ServiceConnectConfiguration -> String
showsPrec :: Int -> ServiceConnectConfiguration -> ShowS
$cshowsPrec :: Int -> ServiceConnectConfiguration -> ShowS
Prelude.Show, forall x.
Rep ServiceConnectConfiguration x -> ServiceConnectConfiguration
forall x.
ServiceConnectConfiguration -> Rep ServiceConnectConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ServiceConnectConfiguration x -> ServiceConnectConfiguration
$cfrom :: forall x.
ServiceConnectConfiguration -> Rep ServiceConnectConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ServiceConnectConfiguration' 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:
--
-- 'logConfiguration', 'serviceConnectConfiguration_logConfiguration' - Undocumented member.
--
-- 'namespace', 'serviceConnectConfiguration_namespace' - The namespace name or full Amazon Resource Name (ARN) of the Cloud Map
-- namespace for use with Service Connect. The namespace must be in the
-- same Amazon Web Services Region as the Amazon ECS service and cluster.
-- The type of namespace doesn\'t affect Service Connect. For more
-- information about Cloud Map, see
-- <https://docs.aws.amazon.com/ Working with Services> in the /Cloud Map
-- Developer Guide/.
--
-- 'services', 'serviceConnectConfiguration_services' - The list of Service Connect service objects. These are names and aliases
-- (also known as endpoints) that are used by other Amazon ECS services to
-- connect to this service.
--
-- This field is not required for a \"client\" Amazon ECS service that\'s a
-- member of a namespace only to connect to other services within the
-- namespace. An example of this would be a frontend application that
-- accepts incoming requests from either a load balancer that\'s attached
-- to the service or by other means.
--
-- An object selects a port from the task definition, assigns a name for
-- the Cloud Map service, and a list of aliases (endpoints) and ports for
-- client applications to refer to this service.
--
-- 'enabled', 'serviceConnectConfiguration_enabled' - Specifies whether to use Service Connect with this service.
newServiceConnectConfiguration ::
  -- | 'enabled'
  Prelude.Bool ->
  ServiceConnectConfiguration
newServiceConnectConfiguration :: Bool -> ServiceConnectConfiguration
newServiceConnectConfiguration Bool
pEnabled_ =
  ServiceConnectConfiguration'
    { $sel:logConfiguration:ServiceConnectConfiguration' :: Maybe LogConfiguration
logConfiguration =
        forall a. Maybe a
Prelude.Nothing,
      $sel:namespace:ServiceConnectConfiguration' :: Maybe Text
namespace = forall a. Maybe a
Prelude.Nothing,
      $sel:services:ServiceConnectConfiguration' :: Maybe [ServiceConnectService]
services = forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:ServiceConnectConfiguration' :: Bool
enabled = Bool
pEnabled_
    }

-- | Undocumented member.
serviceConnectConfiguration_logConfiguration :: Lens.Lens' ServiceConnectConfiguration (Prelude.Maybe LogConfiguration)
serviceConnectConfiguration_logConfiguration :: Lens' ServiceConnectConfiguration (Maybe LogConfiguration)
serviceConnectConfiguration_logConfiguration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectConfiguration' {Maybe LogConfiguration
logConfiguration :: Maybe LogConfiguration
$sel:logConfiguration:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe LogConfiguration
logConfiguration} -> Maybe LogConfiguration
logConfiguration) (\s :: ServiceConnectConfiguration
s@ServiceConnectConfiguration' {} Maybe LogConfiguration
a -> ServiceConnectConfiguration
s {$sel:logConfiguration:ServiceConnectConfiguration' :: Maybe LogConfiguration
logConfiguration = Maybe LogConfiguration
a} :: ServiceConnectConfiguration)

-- | The namespace name or full Amazon Resource Name (ARN) of the Cloud Map
-- namespace for use with Service Connect. The namespace must be in the
-- same Amazon Web Services Region as the Amazon ECS service and cluster.
-- The type of namespace doesn\'t affect Service Connect. For more
-- information about Cloud Map, see
-- <https://docs.aws.amazon.com/ Working with Services> in the /Cloud Map
-- Developer Guide/.
serviceConnectConfiguration_namespace :: Lens.Lens' ServiceConnectConfiguration (Prelude.Maybe Prelude.Text)
serviceConnectConfiguration_namespace :: Lens' ServiceConnectConfiguration (Maybe Text)
serviceConnectConfiguration_namespace = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectConfiguration' {Maybe Text
namespace :: Maybe Text
$sel:namespace:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe Text
namespace} -> Maybe Text
namespace) (\s :: ServiceConnectConfiguration
s@ServiceConnectConfiguration' {} Maybe Text
a -> ServiceConnectConfiguration
s {$sel:namespace:ServiceConnectConfiguration' :: Maybe Text
namespace = Maybe Text
a} :: ServiceConnectConfiguration)

-- | The list of Service Connect service objects. These are names and aliases
-- (also known as endpoints) that are used by other Amazon ECS services to
-- connect to this service.
--
-- This field is not required for a \"client\" Amazon ECS service that\'s a
-- member of a namespace only to connect to other services within the
-- namespace. An example of this would be a frontend application that
-- accepts incoming requests from either a load balancer that\'s attached
-- to the service or by other means.
--
-- An object selects a port from the task definition, assigns a name for
-- the Cloud Map service, and a list of aliases (endpoints) and ports for
-- client applications to refer to this service.
serviceConnectConfiguration_services :: Lens.Lens' ServiceConnectConfiguration (Prelude.Maybe [ServiceConnectService])
serviceConnectConfiguration_services :: Lens' ServiceConnectConfiguration (Maybe [ServiceConnectService])
serviceConnectConfiguration_services = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectConfiguration' {Maybe [ServiceConnectService]
services :: Maybe [ServiceConnectService]
$sel:services:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe [ServiceConnectService]
services} -> Maybe [ServiceConnectService]
services) (\s :: ServiceConnectConfiguration
s@ServiceConnectConfiguration' {} Maybe [ServiceConnectService]
a -> ServiceConnectConfiguration
s {$sel:services:ServiceConnectConfiguration' :: Maybe [ServiceConnectService]
services = Maybe [ServiceConnectService]
a} :: ServiceConnectConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies whether to use Service Connect with this service.
serviceConnectConfiguration_enabled :: Lens.Lens' ServiceConnectConfiguration Prelude.Bool
serviceConnectConfiguration_enabled :: Lens' ServiceConnectConfiguration Bool
serviceConnectConfiguration_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceConnectConfiguration' {Bool
enabled :: Bool
$sel:enabled:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Bool
enabled} -> Bool
enabled) (\s :: ServiceConnectConfiguration
s@ServiceConnectConfiguration' {} Bool
a -> ServiceConnectConfiguration
s {$sel:enabled:ServiceConnectConfiguration' :: Bool
enabled = Bool
a} :: ServiceConnectConfiguration)

instance Data.FromJSON ServiceConnectConfiguration where
  parseJSON :: Value -> Parser ServiceConnectConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ServiceConnectConfiguration"
      ( \Object
x ->
          Maybe LogConfiguration
-> Maybe Text
-> Maybe [ServiceConnectService]
-> Bool
-> ServiceConnectConfiguration
ServiceConnectConfiguration'
            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
"logConfiguration")
            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
"namespace")
            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
"services" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"enabled")
      )

instance Prelude.Hashable ServiceConnectConfiguration where
  hashWithSalt :: Int -> ServiceConnectConfiguration -> Int
hashWithSalt Int
_salt ServiceConnectConfiguration' {Bool
Maybe [ServiceConnectService]
Maybe Text
Maybe LogConfiguration
enabled :: Bool
services :: Maybe [ServiceConnectService]
namespace :: Maybe Text
logConfiguration :: Maybe LogConfiguration
$sel:enabled:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Bool
$sel:services:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe [ServiceConnectService]
$sel:namespace:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe Text
$sel:logConfiguration:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe LogConfiguration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LogConfiguration
logConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
namespace
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ServiceConnectService]
services
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enabled

instance Prelude.NFData ServiceConnectConfiguration where
  rnf :: ServiceConnectConfiguration -> ()
rnf ServiceConnectConfiguration' {Bool
Maybe [ServiceConnectService]
Maybe Text
Maybe LogConfiguration
enabled :: Bool
services :: Maybe [ServiceConnectService]
namespace :: Maybe Text
logConfiguration :: Maybe LogConfiguration
$sel:enabled:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Bool
$sel:services:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe [ServiceConnectService]
$sel:namespace:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe Text
$sel:logConfiguration:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe LogConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe LogConfiguration
logConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
namespace
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [ServiceConnectService]
services
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
enabled

instance Data.ToJSON ServiceConnectConfiguration where
  toJSON :: ServiceConnectConfiguration -> Value
toJSON ServiceConnectConfiguration' {Bool
Maybe [ServiceConnectService]
Maybe Text
Maybe LogConfiguration
enabled :: Bool
services :: Maybe [ServiceConnectService]
namespace :: Maybe Text
logConfiguration :: Maybe LogConfiguration
$sel:enabled:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Bool
$sel:services:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe [ServiceConnectService]
$sel:namespace:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe Text
$sel:logConfiguration:ServiceConnectConfiguration' :: ServiceConnectConfiguration -> Maybe LogConfiguration
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"logConfiguration" 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 LogConfiguration
logConfiguration,
            (Key
"namespace" 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
namespace,
            (Key
"services" 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 [ServiceConnectService]
services,
            forall a. a -> Maybe a
Prelude.Just (Key
"enabled" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Bool
enabled)
          ]
      )