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

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

-- | A list of files containing the environment variables to pass to a
-- container. You can specify up to ten environment files. The file must
-- have a @.env@ file extension. Each line in an environment file should
-- contain an environment variable in @VARIABLE=VALUE@ format. Lines
-- beginning with @#@ are treated as comments and are ignored. For more
-- information on the environment variable file syntax, see
-- <https://docs.docker.com/compose/env-file/ Declare default environment variables in file>.
--
-- If there are environment variables specified using the @environment@
-- parameter in a container definition, they take precedence over the
-- variables contained within an environment file. If multiple environment
-- files are specified that contain the same variable, they are processed
-- from the top down. It is recommended to use unique variable names. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/taskdef-envfiles.html Specifying environment variables>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- This field is only valid for containers in Fargate tasks that use
-- platform version @1.4.0@ or later.
--
-- /See:/ 'newEnvironmentFile' smart constructor.
data EnvironmentFile = EnvironmentFile'
  { -- | The Amazon Resource Name (ARN) of the Amazon S3 object containing the
    -- environment variable file.
    EnvironmentFile -> Text
value :: Prelude.Text,
    -- | The file type to use. The only supported value is @s3@.
    EnvironmentFile -> EnvironmentFileType
type' :: EnvironmentFileType
  }
  deriving (EnvironmentFile -> EnvironmentFile -> Bool
(EnvironmentFile -> EnvironmentFile -> Bool)
-> (EnvironmentFile -> EnvironmentFile -> Bool)
-> Eq EnvironmentFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnvironmentFile -> EnvironmentFile -> Bool
$c/= :: EnvironmentFile -> EnvironmentFile -> Bool
== :: EnvironmentFile -> EnvironmentFile -> Bool
$c== :: EnvironmentFile -> EnvironmentFile -> Bool
Prelude.Eq, ReadPrec [EnvironmentFile]
ReadPrec EnvironmentFile
Int -> ReadS EnvironmentFile
ReadS [EnvironmentFile]
(Int -> ReadS EnvironmentFile)
-> ReadS [EnvironmentFile]
-> ReadPrec EnvironmentFile
-> ReadPrec [EnvironmentFile]
-> Read EnvironmentFile
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnvironmentFile]
$creadListPrec :: ReadPrec [EnvironmentFile]
readPrec :: ReadPrec EnvironmentFile
$creadPrec :: ReadPrec EnvironmentFile
readList :: ReadS [EnvironmentFile]
$creadList :: ReadS [EnvironmentFile]
readsPrec :: Int -> ReadS EnvironmentFile
$creadsPrec :: Int -> ReadS EnvironmentFile
Prelude.Read, Int -> EnvironmentFile -> ShowS
[EnvironmentFile] -> ShowS
EnvironmentFile -> String
(Int -> EnvironmentFile -> ShowS)
-> (EnvironmentFile -> String)
-> ([EnvironmentFile] -> ShowS)
-> Show EnvironmentFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnvironmentFile] -> ShowS
$cshowList :: [EnvironmentFile] -> ShowS
show :: EnvironmentFile -> String
$cshow :: EnvironmentFile -> String
showsPrec :: Int -> EnvironmentFile -> ShowS
$cshowsPrec :: Int -> EnvironmentFile -> ShowS
Prelude.Show, (forall x. EnvironmentFile -> Rep EnvironmentFile x)
-> (forall x. Rep EnvironmentFile x -> EnvironmentFile)
-> Generic EnvironmentFile
forall x. Rep EnvironmentFile x -> EnvironmentFile
forall x. EnvironmentFile -> Rep EnvironmentFile x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnvironmentFile x -> EnvironmentFile
$cfrom :: forall x. EnvironmentFile -> Rep EnvironmentFile x
Prelude.Generic)

-- |
-- Create a value of 'EnvironmentFile' 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:
--
-- 'value', 'environmentFile_value' - The Amazon Resource Name (ARN) of the Amazon S3 object containing the
-- environment variable file.
--
-- 'type'', 'environmentFile_type' - The file type to use. The only supported value is @s3@.
newEnvironmentFile ::
  -- | 'value'
  Prelude.Text ->
  -- | 'type''
  EnvironmentFileType ->
  EnvironmentFile
newEnvironmentFile :: Text -> EnvironmentFileType -> EnvironmentFile
newEnvironmentFile Text
pValue_ EnvironmentFileType
pType_ =
  EnvironmentFile' :: Text -> EnvironmentFileType -> EnvironmentFile
EnvironmentFile' {$sel:value:EnvironmentFile' :: Text
value = Text
pValue_, $sel:type':EnvironmentFile' :: EnvironmentFileType
type' = EnvironmentFileType
pType_}

-- | The Amazon Resource Name (ARN) of the Amazon S3 object containing the
-- environment variable file.
environmentFile_value :: Lens.Lens' EnvironmentFile Prelude.Text
environmentFile_value :: (Text -> f Text) -> EnvironmentFile -> f EnvironmentFile
environmentFile_value = (EnvironmentFile -> Text)
-> (EnvironmentFile -> Text -> EnvironmentFile)
-> Lens EnvironmentFile EnvironmentFile Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnvironmentFile' {Text
value :: Text
$sel:value:EnvironmentFile' :: EnvironmentFile -> Text
value} -> Text
value) (\s :: EnvironmentFile
s@EnvironmentFile' {} Text
a -> EnvironmentFile
s {$sel:value:EnvironmentFile' :: Text
value = Text
a} :: EnvironmentFile)

-- | The file type to use. The only supported value is @s3@.
environmentFile_type :: Lens.Lens' EnvironmentFile EnvironmentFileType
environmentFile_type :: (EnvironmentFileType -> f EnvironmentFileType)
-> EnvironmentFile -> f EnvironmentFile
environmentFile_type = (EnvironmentFile -> EnvironmentFileType)
-> (EnvironmentFile -> EnvironmentFileType -> EnvironmentFile)
-> Lens
     EnvironmentFile
     EnvironmentFile
     EnvironmentFileType
     EnvironmentFileType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnvironmentFile' {EnvironmentFileType
type' :: EnvironmentFileType
$sel:type':EnvironmentFile' :: EnvironmentFile -> EnvironmentFileType
type'} -> EnvironmentFileType
type') (\s :: EnvironmentFile
s@EnvironmentFile' {} EnvironmentFileType
a -> EnvironmentFile
s {$sel:type':EnvironmentFile' :: EnvironmentFileType
type' = EnvironmentFileType
a} :: EnvironmentFile)

instance Core.FromJSON EnvironmentFile where
  parseJSON :: Value -> Parser EnvironmentFile
parseJSON =
    String
-> (Object -> Parser EnvironmentFile)
-> Value
-> Parser EnvironmentFile
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EnvironmentFile"
      ( \Object
x ->
          Text -> EnvironmentFileType -> EnvironmentFile
EnvironmentFile'
            (Text -> EnvironmentFileType -> EnvironmentFile)
-> Parser Text -> Parser (EnvironmentFileType -> EnvironmentFile)
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
"value") Parser (EnvironmentFileType -> EnvironmentFile)
-> Parser EnvironmentFileType -> Parser EnvironmentFile
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EnvironmentFileType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable EnvironmentFile

instance Prelude.NFData EnvironmentFile

instance Core.ToJSON EnvironmentFile where
  toJSON :: EnvironmentFile -> Value
toJSON EnvironmentFile' {Text
EnvironmentFileType
type' :: EnvironmentFileType
value :: Text
$sel:type':EnvironmentFile' :: EnvironmentFile -> EnvironmentFileType
$sel:value:EnvironmentFile' :: EnvironmentFile -> 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
"value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> EnvironmentFileType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EnvironmentFileType
type')
          ]
      )