{-# 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.FirelensConfiguration
-- 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.FirelensConfiguration 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.FirelensConfigurationType
import qualified Amazonka.Prelude as Prelude

-- | The FireLens configuration for the container. This is used to specify
-- and configure a log router for container logs. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html Custom log routing>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newFirelensConfiguration' smart constructor.
data FirelensConfiguration = FirelensConfiguration'
  { -- | The options to use when configuring the log router. This field is
    -- optional and can be used to specify a custom configuration file or to
    -- add additional metadata, such as the task, task definition, cluster, and
    -- container instance details to the log event. If specified, the syntax to
    -- use is
    -- @\"options\":{\"enable-ecs-log-metadata\":\"true|false\",\"config-file-type:\"s3|file\",\"config-file-value\":\"arn:aws:s3:::mybucket\/fluent.conf|filepath\"}@.
    -- For more information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-taskdef Creating a task definition that uses a FireLens configuration>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    --
    -- Tasks hosted on Fargate only support the @file@ configuration file type.
    FirelensConfiguration -> Maybe (HashMap Text Text)
options :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The log router to use. The valid values are @fluentd@ or @fluentbit@.
    FirelensConfiguration -> FirelensConfigurationType
type' :: FirelensConfigurationType
  }
  deriving (FirelensConfiguration -> FirelensConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FirelensConfiguration -> FirelensConfiguration -> Bool
$c/= :: FirelensConfiguration -> FirelensConfiguration -> Bool
== :: FirelensConfiguration -> FirelensConfiguration -> Bool
$c== :: FirelensConfiguration -> FirelensConfiguration -> Bool
Prelude.Eq, ReadPrec [FirelensConfiguration]
ReadPrec FirelensConfiguration
Int -> ReadS FirelensConfiguration
ReadS [FirelensConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FirelensConfiguration]
$creadListPrec :: ReadPrec [FirelensConfiguration]
readPrec :: ReadPrec FirelensConfiguration
$creadPrec :: ReadPrec FirelensConfiguration
readList :: ReadS [FirelensConfiguration]
$creadList :: ReadS [FirelensConfiguration]
readsPrec :: Int -> ReadS FirelensConfiguration
$creadsPrec :: Int -> ReadS FirelensConfiguration
Prelude.Read, Int -> FirelensConfiguration -> ShowS
[FirelensConfiguration] -> ShowS
FirelensConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FirelensConfiguration] -> ShowS
$cshowList :: [FirelensConfiguration] -> ShowS
show :: FirelensConfiguration -> String
$cshow :: FirelensConfiguration -> String
showsPrec :: Int -> FirelensConfiguration -> ShowS
$cshowsPrec :: Int -> FirelensConfiguration -> ShowS
Prelude.Show, forall x. Rep FirelensConfiguration x -> FirelensConfiguration
forall x. FirelensConfiguration -> Rep FirelensConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FirelensConfiguration x -> FirelensConfiguration
$cfrom :: forall x. FirelensConfiguration -> Rep FirelensConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'FirelensConfiguration' 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:
--
-- 'options', 'firelensConfiguration_options' - The options to use when configuring the log router. This field is
-- optional and can be used to specify a custom configuration file or to
-- add additional metadata, such as the task, task definition, cluster, and
-- container instance details to the log event. If specified, the syntax to
-- use is
-- @\"options\":{\"enable-ecs-log-metadata\":\"true|false\",\"config-file-type:\"s3|file\",\"config-file-value\":\"arn:aws:s3:::mybucket\/fluent.conf|filepath\"}@.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-taskdef Creating a task definition that uses a FireLens configuration>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- Tasks hosted on Fargate only support the @file@ configuration file type.
--
-- 'type'', 'firelensConfiguration_type' - The log router to use. The valid values are @fluentd@ or @fluentbit@.
newFirelensConfiguration ::
  -- | 'type''
  FirelensConfigurationType ->
  FirelensConfiguration
newFirelensConfiguration :: FirelensConfigurationType -> FirelensConfiguration
newFirelensConfiguration FirelensConfigurationType
pType_ =
  FirelensConfiguration'
    { $sel:options:FirelensConfiguration' :: Maybe (HashMap Text Text)
options = forall a. Maybe a
Prelude.Nothing,
      $sel:type':FirelensConfiguration' :: FirelensConfigurationType
type' = FirelensConfigurationType
pType_
    }

-- | The options to use when configuring the log router. This field is
-- optional and can be used to specify a custom configuration file or to
-- add additional metadata, such as the task, task definition, cluster, and
-- container instance details to the log event. If specified, the syntax to
-- use is
-- @\"options\":{\"enable-ecs-log-metadata\":\"true|false\",\"config-file-type:\"s3|file\",\"config-file-value\":\"arn:aws:s3:::mybucket\/fluent.conf|filepath\"}@.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-taskdef Creating a task definition that uses a FireLens configuration>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- Tasks hosted on Fargate only support the @file@ configuration file type.
firelensConfiguration_options :: Lens.Lens' FirelensConfiguration (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
firelensConfiguration_options :: Lens' FirelensConfiguration (Maybe (HashMap Text Text))
firelensConfiguration_options = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FirelensConfiguration' {Maybe (HashMap Text Text)
options :: Maybe (HashMap Text Text)
$sel:options:FirelensConfiguration' :: FirelensConfiguration -> Maybe (HashMap Text Text)
options} -> Maybe (HashMap Text Text)
options) (\s :: FirelensConfiguration
s@FirelensConfiguration' {} Maybe (HashMap Text Text)
a -> FirelensConfiguration
s {$sel:options:FirelensConfiguration' :: Maybe (HashMap Text Text)
options = Maybe (HashMap Text Text)
a} :: FirelensConfiguration) 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

-- | The log router to use. The valid values are @fluentd@ or @fluentbit@.
firelensConfiguration_type :: Lens.Lens' FirelensConfiguration FirelensConfigurationType
firelensConfiguration_type :: Lens' FirelensConfiguration FirelensConfigurationType
firelensConfiguration_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FirelensConfiguration' {FirelensConfigurationType
type' :: FirelensConfigurationType
$sel:type':FirelensConfiguration' :: FirelensConfiguration -> FirelensConfigurationType
type'} -> FirelensConfigurationType
type') (\s :: FirelensConfiguration
s@FirelensConfiguration' {} FirelensConfigurationType
a -> FirelensConfiguration
s {$sel:type':FirelensConfiguration' :: FirelensConfigurationType
type' = FirelensConfigurationType
a} :: FirelensConfiguration)

instance Data.FromJSON FirelensConfiguration where
  parseJSON :: Value -> Parser FirelensConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FirelensConfiguration"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> FirelensConfigurationType -> FirelensConfiguration
FirelensConfiguration'
            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
"options" 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
"type")
      )

instance Prelude.Hashable FirelensConfiguration where
  hashWithSalt :: Int -> FirelensConfiguration -> Int
hashWithSalt Int
_salt FirelensConfiguration' {Maybe (HashMap Text Text)
FirelensConfigurationType
type' :: FirelensConfigurationType
options :: Maybe (HashMap Text Text)
$sel:type':FirelensConfiguration' :: FirelensConfiguration -> FirelensConfigurationType
$sel:options:FirelensConfiguration' :: FirelensConfiguration -> Maybe (HashMap Text Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
options
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FirelensConfigurationType
type'

instance Prelude.NFData FirelensConfiguration where
  rnf :: FirelensConfiguration -> ()
rnf FirelensConfiguration' {Maybe (HashMap Text Text)
FirelensConfigurationType
type' :: FirelensConfigurationType
options :: Maybe (HashMap Text Text)
$sel:type':FirelensConfiguration' :: FirelensConfiguration -> FirelensConfigurationType
$sel:options:FirelensConfiguration' :: FirelensConfiguration -> Maybe (HashMap Text Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
options seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FirelensConfigurationType
type'

instance Data.ToJSON FirelensConfiguration where
  toJSON :: FirelensConfiguration -> Value
toJSON FirelensConfiguration' {Maybe (HashMap Text Text)
FirelensConfigurationType
type' :: FirelensConfigurationType
options :: Maybe (HashMap Text Text)
$sel:type':FirelensConfiguration' :: FirelensConfiguration -> FirelensConfigurationType
$sel:options:FirelensConfiguration' :: FirelensConfiguration -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"options" 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 (HashMap Text Text)
options,
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FirelensConfigurationType
type')
          ]
      )