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

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.ContainerCondition
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The dependencies defined for container startup and shutdown. A container
-- can contain multiple dependencies. When a dependency is defined for
-- container startup, for container shutdown it is reversed.
--
-- Your Amazon ECS container instances require at least version 1.26.0 of
-- the container agent to enable container dependencies. However, we
-- recommend using the latest container agent version. For information
-- about checking your agent version and updating to the latest version,
-- see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-update.html Updating the Amazon ECS Container Agent>
-- in the /Amazon Elastic Container Service Developer Guide/. If you are
-- using an Amazon ECS-optimized Linux AMI, your instance needs at least
-- version 1.26.0-1 of the @ecs-init@ package. If your container instances
-- are launched from version @20190301@ or later, then they contain the
-- required versions of the container agent and @ecs-init@. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html Amazon ECS-optimized Linux AMI>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- For tasks using the Fargate launch type, this parameter requires that
-- the task or service uses platform version 1.3.0 or later.
--
-- /See:/ 'newContainerDependency' smart constructor.
data ContainerDependency = ContainerDependency'
  { -- | The name of a container.
    ContainerDependency -> Text
containerName :: Prelude.Text,
    -- | The dependency condition of the container. The following are the
    -- available conditions and their behavior:
    --
    -- -   @START@ - This condition emulates the behavior of links and volumes
    --     today. It validates that a dependent container is started before
    --     permitting other containers to start.
    --
    -- -   @COMPLETE@ - This condition validates that a dependent container
    --     runs to completion (exits) before permitting other containers to
    --     start. This can be useful for nonessential containers that run a
    --     script and then exit. This condition cannot be set on an essential
    --     container.
    --
    -- -   @SUCCESS@ - This condition is the same as @COMPLETE@, but it also
    --     requires that the container exits with a @zero@ status. This
    --     condition cannot be set on an essential container.
    --
    -- -   @HEALTHY@ - This condition validates that the dependent container
    --     passes its Docker health check before permitting other containers to
    --     start. This requires that the dependent container has health checks
    --     configured. This condition is confirmed only at task startup.
    ContainerDependency -> ContainerCondition
condition :: ContainerCondition
  }
  deriving (ContainerDependency -> ContainerDependency -> Bool
(ContainerDependency -> ContainerDependency -> Bool)
-> (ContainerDependency -> ContainerDependency -> Bool)
-> Eq ContainerDependency
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ContainerDependency -> ContainerDependency -> Bool
$c/= :: ContainerDependency -> ContainerDependency -> Bool
== :: ContainerDependency -> ContainerDependency -> Bool
$c== :: ContainerDependency -> ContainerDependency -> Bool
Prelude.Eq, ReadPrec [ContainerDependency]
ReadPrec ContainerDependency
Int -> ReadS ContainerDependency
ReadS [ContainerDependency]
(Int -> ReadS ContainerDependency)
-> ReadS [ContainerDependency]
-> ReadPrec ContainerDependency
-> ReadPrec [ContainerDependency]
-> Read ContainerDependency
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ContainerDependency]
$creadListPrec :: ReadPrec [ContainerDependency]
readPrec :: ReadPrec ContainerDependency
$creadPrec :: ReadPrec ContainerDependency
readList :: ReadS [ContainerDependency]
$creadList :: ReadS [ContainerDependency]
readsPrec :: Int -> ReadS ContainerDependency
$creadsPrec :: Int -> ReadS ContainerDependency
Prelude.Read, Int -> ContainerDependency -> ShowS
[ContainerDependency] -> ShowS
ContainerDependency -> String
(Int -> ContainerDependency -> ShowS)
-> (ContainerDependency -> String)
-> ([ContainerDependency] -> ShowS)
-> Show ContainerDependency
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ContainerDependency] -> ShowS
$cshowList :: [ContainerDependency] -> ShowS
show :: ContainerDependency -> String
$cshow :: ContainerDependency -> String
showsPrec :: Int -> ContainerDependency -> ShowS
$cshowsPrec :: Int -> ContainerDependency -> ShowS
Prelude.Show, (forall x. ContainerDependency -> Rep ContainerDependency x)
-> (forall x. Rep ContainerDependency x -> ContainerDependency)
-> Generic ContainerDependency
forall x. Rep ContainerDependency x -> ContainerDependency
forall x. ContainerDependency -> Rep ContainerDependency x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ContainerDependency x -> ContainerDependency
$cfrom :: forall x. ContainerDependency -> Rep ContainerDependency x
Prelude.Generic)

-- |
-- Create a value of 'ContainerDependency' 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', 'containerDependency_containerName' - The name of a container.
--
-- 'condition', 'containerDependency_condition' - The dependency condition of the container. The following are the
-- available conditions and their behavior:
--
-- -   @START@ - This condition emulates the behavior of links and volumes
--     today. It validates that a dependent container is started before
--     permitting other containers to start.
--
-- -   @COMPLETE@ - This condition validates that a dependent container
--     runs to completion (exits) before permitting other containers to
--     start. This can be useful for nonessential containers that run a
--     script and then exit. This condition cannot be set on an essential
--     container.
--
-- -   @SUCCESS@ - This condition is the same as @COMPLETE@, but it also
--     requires that the container exits with a @zero@ status. This
--     condition cannot be set on an essential container.
--
-- -   @HEALTHY@ - This condition validates that the dependent container
--     passes its Docker health check before permitting other containers to
--     start. This requires that the dependent container has health checks
--     configured. This condition is confirmed only at task startup.
newContainerDependency ::
  -- | 'containerName'
  Prelude.Text ->
  -- | 'condition'
  ContainerCondition ->
  ContainerDependency
newContainerDependency :: Text -> ContainerCondition -> ContainerDependency
newContainerDependency Text
pContainerName_ ContainerCondition
pCondition_ =
  ContainerDependency' :: Text -> ContainerCondition -> ContainerDependency
ContainerDependency'
    { $sel:containerName:ContainerDependency' :: Text
containerName =
        Text
pContainerName_,
      $sel:condition:ContainerDependency' :: ContainerCondition
condition = ContainerCondition
pCondition_
    }

-- | The name of a container.
containerDependency_containerName :: Lens.Lens' ContainerDependency Prelude.Text
containerDependency_containerName :: (Text -> f Text) -> ContainerDependency -> f ContainerDependency
containerDependency_containerName = (ContainerDependency -> Text)
-> (ContainerDependency -> Text -> ContainerDependency)
-> Lens ContainerDependency ContainerDependency Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContainerDependency' {Text
containerName :: Text
$sel:containerName:ContainerDependency' :: ContainerDependency -> Text
containerName} -> Text
containerName) (\s :: ContainerDependency
s@ContainerDependency' {} Text
a -> ContainerDependency
s {$sel:containerName:ContainerDependency' :: Text
containerName = Text
a} :: ContainerDependency)

-- | The dependency condition of the container. The following are the
-- available conditions and their behavior:
--
-- -   @START@ - This condition emulates the behavior of links and volumes
--     today. It validates that a dependent container is started before
--     permitting other containers to start.
--
-- -   @COMPLETE@ - This condition validates that a dependent container
--     runs to completion (exits) before permitting other containers to
--     start. This can be useful for nonessential containers that run a
--     script and then exit. This condition cannot be set on an essential
--     container.
--
-- -   @SUCCESS@ - This condition is the same as @COMPLETE@, but it also
--     requires that the container exits with a @zero@ status. This
--     condition cannot be set on an essential container.
--
-- -   @HEALTHY@ - This condition validates that the dependent container
--     passes its Docker health check before permitting other containers to
--     start. This requires that the dependent container has health checks
--     configured. This condition is confirmed only at task startup.
containerDependency_condition :: Lens.Lens' ContainerDependency ContainerCondition
containerDependency_condition :: (ContainerCondition -> f ContainerCondition)
-> ContainerDependency -> f ContainerDependency
containerDependency_condition = (ContainerDependency -> ContainerCondition)
-> (ContainerDependency
    -> ContainerCondition -> ContainerDependency)
-> Lens
     ContainerDependency
     ContainerDependency
     ContainerCondition
     ContainerCondition
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContainerDependency' {ContainerCondition
condition :: ContainerCondition
$sel:condition:ContainerDependency' :: ContainerDependency -> ContainerCondition
condition} -> ContainerCondition
condition) (\s :: ContainerDependency
s@ContainerDependency' {} ContainerCondition
a -> ContainerDependency
s {$sel:condition:ContainerDependency' :: ContainerCondition
condition = ContainerCondition
a} :: ContainerDependency)

instance Core.FromJSON ContainerDependency where
  parseJSON :: Value -> Parser ContainerDependency
parseJSON =
    String
-> (Object -> Parser ContainerDependency)
-> Value
-> Parser ContainerDependency
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ContainerDependency"
      ( \Object
x ->
          Text -> ContainerCondition -> ContainerDependency
ContainerDependency'
            (Text -> ContainerCondition -> ContainerDependency)
-> Parser Text
-> Parser (ContainerCondition -> ContainerDependency)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"containerName")
            Parser (ContainerCondition -> ContainerDependency)
-> Parser ContainerCondition -> Parser ContainerDependency
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ContainerCondition
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"condition")
      )

instance Prelude.Hashable ContainerDependency

instance Prelude.NFData ContainerDependency

instance Core.ToJSON ContainerDependency where
  toJSON :: ContainerDependency -> Value
toJSON ContainerDependency' {Text
ContainerCondition
condition :: ContainerCondition
containerName :: Text
$sel:condition:ContainerDependency' :: ContainerDependency -> ContainerCondition
$sel:containerName:ContainerDependency' :: ContainerDependency -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"containerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
containerName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"condition" Text -> ContainerCondition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ContainerCondition
condition)
          ]
      )