{-# 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.ServiceRegistry
-- 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.ServiceRegistry where

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

-- | The details for the service registry.
--
-- Each service may be associated with one service registry. Multiple
-- service registries for each service are not supported.
--
-- When you add, update, or remove the service registries configuration,
-- Amazon ECS starts a new deployment. New tasks are registered and
-- deregistered to the updated service registry configuration.
--
-- /See:/ 'newServiceRegistry' smart constructor.
data ServiceRegistry = ServiceRegistry'
  { -- | The container name value to be used for your service discovery service.
    -- It\'s already specified in the task definition. If the task definition
    -- that your service task specifies uses the @bridge@ or @host@ network
    -- mode, you must specify a @containerName@ and @containerPort@ combination
    -- from the task definition. If the task definition that your service task
    -- specifies uses the @awsvpc@ network mode and a type SRV DNS record is
    -- used, you must specify either a @containerName@ and @containerPort@
    -- combination or a @port@ value. However, you can\'t specify both.
    ServiceRegistry -> Maybe Text
containerName :: Prelude.Maybe Prelude.Text,
    -- | The port value to be used for your service discovery service. It\'s
    -- already specified in the task definition. If the task definition your
    -- service task specifies uses the @bridge@ or @host@ network mode, you
    -- must specify a @containerName@ and @containerPort@ combination from the
    -- task definition. If the task definition your service task specifies uses
    -- the @awsvpc@ network mode and a type SRV DNS record is used, you must
    -- specify either a @containerName@ and @containerPort@ combination or a
    -- @port@ value. However, you can\'t specify both.
    ServiceRegistry -> Maybe Int
containerPort :: Prelude.Maybe Prelude.Int,
    -- | The port value used if your service discovery service specified an SRV
    -- record. This field might be used if both the @awsvpc@ network mode and
    -- SRV records are used.
    ServiceRegistry -> Maybe Int
port :: Prelude.Maybe Prelude.Int,
    -- | The Amazon Resource Name (ARN) of the service registry. The currently
    -- supported service registry is Cloud Map. For more information, see
    -- <https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateService.html CreateService>.
    ServiceRegistry -> Maybe Text
registryArn :: Prelude.Maybe Prelude.Text
  }
  deriving (ServiceRegistry -> ServiceRegistry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServiceRegistry -> ServiceRegistry -> Bool
$c/= :: ServiceRegistry -> ServiceRegistry -> Bool
== :: ServiceRegistry -> ServiceRegistry -> Bool
$c== :: ServiceRegistry -> ServiceRegistry -> Bool
Prelude.Eq, ReadPrec [ServiceRegistry]
ReadPrec ServiceRegistry
Int -> ReadS ServiceRegistry
ReadS [ServiceRegistry]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServiceRegistry]
$creadListPrec :: ReadPrec [ServiceRegistry]
readPrec :: ReadPrec ServiceRegistry
$creadPrec :: ReadPrec ServiceRegistry
readList :: ReadS [ServiceRegistry]
$creadList :: ReadS [ServiceRegistry]
readsPrec :: Int -> ReadS ServiceRegistry
$creadsPrec :: Int -> ReadS ServiceRegistry
Prelude.Read, Int -> ServiceRegistry -> ShowS
[ServiceRegistry] -> ShowS
ServiceRegistry -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServiceRegistry] -> ShowS
$cshowList :: [ServiceRegistry] -> ShowS
show :: ServiceRegistry -> String
$cshow :: ServiceRegistry -> String
showsPrec :: Int -> ServiceRegistry -> ShowS
$cshowsPrec :: Int -> ServiceRegistry -> ShowS
Prelude.Show, forall x. Rep ServiceRegistry x -> ServiceRegistry
forall x. ServiceRegistry -> Rep ServiceRegistry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ServiceRegistry x -> ServiceRegistry
$cfrom :: forall x. ServiceRegistry -> Rep ServiceRegistry x
Prelude.Generic)

-- |
-- Create a value of 'ServiceRegistry' 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:
--
-- 'containerName', 'serviceRegistry_containerName' - The container name value to be used for your service discovery service.
-- It\'s already specified in the task definition. If the task definition
-- that your service task specifies uses the @bridge@ or @host@ network
-- mode, you must specify a @containerName@ and @containerPort@ combination
-- from the task definition. If the task definition that your service task
-- specifies uses the @awsvpc@ network mode and a type SRV DNS record is
-- used, you must specify either a @containerName@ and @containerPort@
-- combination or a @port@ value. However, you can\'t specify both.
--
-- 'containerPort', 'serviceRegistry_containerPort' - The port value to be used for your service discovery service. It\'s
-- already specified in the task definition. If the task definition your
-- service task specifies uses the @bridge@ or @host@ network mode, you
-- must specify a @containerName@ and @containerPort@ combination from the
-- task definition. If the task definition your service task specifies uses
-- the @awsvpc@ network mode and a type SRV DNS record is used, you must
-- specify either a @containerName@ and @containerPort@ combination or a
-- @port@ value. However, you can\'t specify both.
--
-- 'port', 'serviceRegistry_port' - The port value used if your service discovery service specified an SRV
-- record. This field might be used if both the @awsvpc@ network mode and
-- SRV records are used.
--
-- 'registryArn', 'serviceRegistry_registryArn' - The Amazon Resource Name (ARN) of the service registry. The currently
-- supported service registry is Cloud Map. For more information, see
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateService.html CreateService>.
newServiceRegistry ::
  ServiceRegistry
newServiceRegistry :: ServiceRegistry
newServiceRegistry =
  ServiceRegistry'
    { $sel:containerName:ServiceRegistry' :: Maybe Text
containerName = forall a. Maybe a
Prelude.Nothing,
      $sel:containerPort:ServiceRegistry' :: Maybe Int
containerPort = forall a. Maybe a
Prelude.Nothing,
      $sel:port:ServiceRegistry' :: Maybe Int
port = forall a. Maybe a
Prelude.Nothing,
      $sel:registryArn:ServiceRegistry' :: Maybe Text
registryArn = forall a. Maybe a
Prelude.Nothing
    }

-- | The container name value to be used for your service discovery service.
-- It\'s already specified in the task definition. If the task definition
-- that your service task specifies uses the @bridge@ or @host@ network
-- mode, you must specify a @containerName@ and @containerPort@ combination
-- from the task definition. If the task definition that your service task
-- specifies uses the @awsvpc@ network mode and a type SRV DNS record is
-- used, you must specify either a @containerName@ and @containerPort@
-- combination or a @port@ value. However, you can\'t specify both.
serviceRegistry_containerName :: Lens.Lens' ServiceRegistry (Prelude.Maybe Prelude.Text)
serviceRegistry_containerName :: Lens' ServiceRegistry (Maybe Text)
serviceRegistry_containerName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceRegistry' {Maybe Text
containerName :: Maybe Text
$sel:containerName:ServiceRegistry' :: ServiceRegistry -> Maybe Text
containerName} -> Maybe Text
containerName) (\s :: ServiceRegistry
s@ServiceRegistry' {} Maybe Text
a -> ServiceRegistry
s {$sel:containerName:ServiceRegistry' :: Maybe Text
containerName = Maybe Text
a} :: ServiceRegistry)

-- | The port value to be used for your service discovery service. It\'s
-- already specified in the task definition. If the task definition your
-- service task specifies uses the @bridge@ or @host@ network mode, you
-- must specify a @containerName@ and @containerPort@ combination from the
-- task definition. If the task definition your service task specifies uses
-- the @awsvpc@ network mode and a type SRV DNS record is used, you must
-- specify either a @containerName@ and @containerPort@ combination or a
-- @port@ value. However, you can\'t specify both.
serviceRegistry_containerPort :: Lens.Lens' ServiceRegistry (Prelude.Maybe Prelude.Int)
serviceRegistry_containerPort :: Lens' ServiceRegistry (Maybe Int)
serviceRegistry_containerPort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceRegistry' {Maybe Int
containerPort :: Maybe Int
$sel:containerPort:ServiceRegistry' :: ServiceRegistry -> Maybe Int
containerPort} -> Maybe Int
containerPort) (\s :: ServiceRegistry
s@ServiceRegistry' {} Maybe Int
a -> ServiceRegistry
s {$sel:containerPort:ServiceRegistry' :: Maybe Int
containerPort = Maybe Int
a} :: ServiceRegistry)

-- | The port value used if your service discovery service specified an SRV
-- record. This field might be used if both the @awsvpc@ network mode and
-- SRV records are used.
serviceRegistry_port :: Lens.Lens' ServiceRegistry (Prelude.Maybe Prelude.Int)
serviceRegistry_port :: Lens' ServiceRegistry (Maybe Int)
serviceRegistry_port = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceRegistry' {Maybe Int
port :: Maybe Int
$sel:port:ServiceRegistry' :: ServiceRegistry -> Maybe Int
port} -> Maybe Int
port) (\s :: ServiceRegistry
s@ServiceRegistry' {} Maybe Int
a -> ServiceRegistry
s {$sel:port:ServiceRegistry' :: Maybe Int
port = Maybe Int
a} :: ServiceRegistry)

-- | The Amazon Resource Name (ARN) of the service registry. The currently
-- supported service registry is Cloud Map. For more information, see
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateService.html CreateService>.
serviceRegistry_registryArn :: Lens.Lens' ServiceRegistry (Prelude.Maybe Prelude.Text)
serviceRegistry_registryArn :: Lens' ServiceRegistry (Maybe Text)
serviceRegistry_registryArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServiceRegistry' {Maybe Text
registryArn :: Maybe Text
$sel:registryArn:ServiceRegistry' :: ServiceRegistry -> Maybe Text
registryArn} -> Maybe Text
registryArn) (\s :: ServiceRegistry
s@ServiceRegistry' {} Maybe Text
a -> ServiceRegistry
s {$sel:registryArn:ServiceRegistry' :: Maybe Text
registryArn = Maybe Text
a} :: ServiceRegistry)

instance Data.FromJSON ServiceRegistry where
  parseJSON :: Value -> Parser ServiceRegistry
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ServiceRegistry"
      ( \Object
x ->
          Maybe Text
-> Maybe Int -> Maybe Int -> Maybe Text -> ServiceRegistry
ServiceRegistry'
            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
"containerName")
            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
"containerPort")
            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
"port")
            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
"registryArn")
      )

instance Prelude.Hashable ServiceRegistry where
  hashWithSalt :: Int -> ServiceRegistry -> Int
hashWithSalt Int
_salt ServiceRegistry' {Maybe Int
Maybe Text
registryArn :: Maybe Text
port :: Maybe Int
containerPort :: Maybe Int
containerName :: Maybe Text
$sel:registryArn:ServiceRegistry' :: ServiceRegistry -> Maybe Text
$sel:port:ServiceRegistry' :: ServiceRegistry -> Maybe Int
$sel:containerPort:ServiceRegistry' :: ServiceRegistry -> Maybe Int
$sel:containerName:ServiceRegistry' :: ServiceRegistry -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
containerName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
containerPort
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
port
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
registryArn

instance Prelude.NFData ServiceRegistry where
  rnf :: ServiceRegistry -> ()
rnf ServiceRegistry' {Maybe Int
Maybe Text
registryArn :: Maybe Text
port :: Maybe Int
containerPort :: Maybe Int
containerName :: Maybe Text
$sel:registryArn:ServiceRegistry' :: ServiceRegistry -> Maybe Text
$sel:port:ServiceRegistry' :: ServiceRegistry -> Maybe Int
$sel:containerPort:ServiceRegistry' :: ServiceRegistry -> Maybe Int
$sel:containerName:ServiceRegistry' :: ServiceRegistry -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
containerName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
containerPort
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
port
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
registryArn

instance Data.ToJSON ServiceRegistry where
  toJSON :: ServiceRegistry -> Value
toJSON ServiceRegistry' {Maybe Int
Maybe Text
registryArn :: Maybe Text
port :: Maybe Int
containerPort :: Maybe Int
containerName :: Maybe Text
$sel:registryArn:ServiceRegistry' :: ServiceRegistry -> Maybe Text
$sel:port:ServiceRegistry' :: ServiceRegistry -> Maybe Int
$sel:containerPort:ServiceRegistry' :: ServiceRegistry -> Maybe Int
$sel:containerName:ServiceRegistry' :: ServiceRegistry -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"containerName" 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
containerName,
            (Key
"containerPort" 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 Int
containerPort,
            (Key
"port" 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 Int
port,
            (Key
"registryArn" 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
registryArn
          ]
      )