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

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.DockerVolumeConfiguration
import Amazonka.ECS.Types.EFSVolumeConfiguration
import Amazonka.ECS.Types.FSxWindowsFileServerVolumeConfiguration
import Amazonka.ECS.Types.HostVolumeProperties
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A data volume used in a task definition. For tasks that use the Amazon
-- Elastic File System (Amazon EFS), specify an @efsVolumeConfiguration@.
-- For Windows tasks that use Amazon FSx for Windows File Server file
-- system, specify a @fsxWindowsFileServerVolumeConfiguration@. For tasks
-- that use a Docker volume, specify a @DockerVolumeConfiguration@. For
-- tasks that use a bind mount host volume, specify a @host@ and optional
-- @sourcePath@. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_data_volumes.html Using Data Volumes in Tasks>.
--
-- /See:/ 'newVolume' smart constructor.
data Volume = Volume'
  { -- | This parameter is specified when you are using Docker volumes.
    --
    -- Windows containers only support the use of the @local@ driver. To use
    -- bind mounts, specify the @host@ parameter instead.
    --
    -- Docker volumes are not supported by tasks run on Fargate.
    Volume -> Maybe DockerVolumeConfiguration
dockerVolumeConfiguration :: Prelude.Maybe DockerVolumeConfiguration,
    -- | This parameter is specified when you are using Amazon FSx for Windows
    -- File Server file system for task storage.
    Volume -> Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration :: Prelude.Maybe FSxWindowsFileServerVolumeConfiguration,
    -- | The name of the volume. Up to 255 letters (uppercase and lowercase),
    -- numbers, underscores, and hyphens are allowed. This name is referenced
    -- in the @sourceVolume@ parameter of container definition @mountPoints@.
    Volume -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | This parameter is specified when you are using an Amazon Elastic File
    -- System file system for task storage.
    Volume -> Maybe EFSVolumeConfiguration
efsVolumeConfiguration :: Prelude.Maybe EFSVolumeConfiguration,
    -- | This parameter is specified when you are using bind mount host volumes.
    -- The contents of the @host@ parameter determine whether your bind mount
    -- host volume persists on the host container instance and where it is
    -- stored. If the @host@ parameter is empty, then the Docker daemon assigns
    -- a host path for your data volume. However, the data is not guaranteed to
    -- persist after the containers associated with it stop running.
    --
    -- Windows containers can mount whole directories on the same drive as
    -- @$env:ProgramData@. Windows containers cannot mount directories on a
    -- different drive, and mount point cannot be across drives. For example,
    -- you can mount @C:\\my\\path:C:\\my\\path@ and @D:\\:D:\\@, but not
    -- @D:\\my\\path:C:\\my\\path@ or @D:\\:C:\\my\\path@.
    Volume -> Maybe HostVolumeProperties
host :: Prelude.Maybe HostVolumeProperties
  }
  deriving (Volume -> Volume -> Bool
(Volume -> Volume -> Bool)
-> (Volume -> Volume -> Bool) -> Eq Volume
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Volume -> Volume -> Bool
$c/= :: Volume -> Volume -> Bool
== :: Volume -> Volume -> Bool
$c== :: Volume -> Volume -> Bool
Prelude.Eq, ReadPrec [Volume]
ReadPrec Volume
Int -> ReadS Volume
ReadS [Volume]
(Int -> ReadS Volume)
-> ReadS [Volume]
-> ReadPrec Volume
-> ReadPrec [Volume]
-> Read Volume
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Volume]
$creadListPrec :: ReadPrec [Volume]
readPrec :: ReadPrec Volume
$creadPrec :: ReadPrec Volume
readList :: ReadS [Volume]
$creadList :: ReadS [Volume]
readsPrec :: Int -> ReadS Volume
$creadsPrec :: Int -> ReadS Volume
Prelude.Read, Int -> Volume -> ShowS
[Volume] -> ShowS
Volume -> String
(Int -> Volume -> ShowS)
-> (Volume -> String) -> ([Volume] -> ShowS) -> Show Volume
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Volume] -> ShowS
$cshowList :: [Volume] -> ShowS
show :: Volume -> String
$cshow :: Volume -> String
showsPrec :: Int -> Volume -> ShowS
$cshowsPrec :: Int -> Volume -> ShowS
Prelude.Show, (forall x. Volume -> Rep Volume x)
-> (forall x. Rep Volume x -> Volume) -> Generic Volume
forall x. Rep Volume x -> Volume
forall x. Volume -> Rep Volume x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Volume x -> Volume
$cfrom :: forall x. Volume -> Rep Volume x
Prelude.Generic)

-- |
-- Create a value of 'Volume' 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:
--
-- 'dockerVolumeConfiguration', 'volume_dockerVolumeConfiguration' - This parameter is specified when you are using Docker volumes.
--
-- Windows containers only support the use of the @local@ driver. To use
-- bind mounts, specify the @host@ parameter instead.
--
-- Docker volumes are not supported by tasks run on Fargate.
--
-- 'fsxWindowsFileServerVolumeConfiguration', 'volume_fsxWindowsFileServerVolumeConfiguration' - This parameter is specified when you are using Amazon FSx for Windows
-- File Server file system for task storage.
--
-- 'name', 'volume_name' - The name of the volume. Up to 255 letters (uppercase and lowercase),
-- numbers, underscores, and hyphens are allowed. This name is referenced
-- in the @sourceVolume@ parameter of container definition @mountPoints@.
--
-- 'efsVolumeConfiguration', 'volume_efsVolumeConfiguration' - This parameter is specified when you are using an Amazon Elastic File
-- System file system for task storage.
--
-- 'host', 'volume_host' - This parameter is specified when you are using bind mount host volumes.
-- The contents of the @host@ parameter determine whether your bind mount
-- host volume persists on the host container instance and where it is
-- stored. If the @host@ parameter is empty, then the Docker daemon assigns
-- a host path for your data volume. However, the data is not guaranteed to
-- persist after the containers associated with it stop running.
--
-- Windows containers can mount whole directories on the same drive as
-- @$env:ProgramData@. Windows containers cannot mount directories on a
-- different drive, and mount point cannot be across drives. For example,
-- you can mount @C:\\my\\path:C:\\my\\path@ and @D:\\:D:\\@, but not
-- @D:\\my\\path:C:\\my\\path@ or @D:\\:C:\\my\\path@.
newVolume ::
  Volume
newVolume :: Volume
newVolume =
  Volume' :: Maybe DockerVolumeConfiguration
-> Maybe FSxWindowsFileServerVolumeConfiguration
-> Maybe Text
-> Maybe EFSVolumeConfiguration
-> Maybe HostVolumeProperties
-> Volume
Volume'
    { $sel:dockerVolumeConfiguration:Volume' :: Maybe DockerVolumeConfiguration
dockerVolumeConfiguration =
        Maybe DockerVolumeConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration =
        Maybe FSxWindowsFileServerVolumeConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Volume' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:efsVolumeConfiguration:Volume' :: Maybe EFSVolumeConfiguration
efsVolumeConfiguration = Maybe EFSVolumeConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:host:Volume' :: Maybe HostVolumeProperties
host = Maybe HostVolumeProperties
forall a. Maybe a
Prelude.Nothing
    }

-- | This parameter is specified when you are using Docker volumes.
--
-- Windows containers only support the use of the @local@ driver. To use
-- bind mounts, specify the @host@ parameter instead.
--
-- Docker volumes are not supported by tasks run on Fargate.
volume_dockerVolumeConfiguration :: Lens.Lens' Volume (Prelude.Maybe DockerVolumeConfiguration)
volume_dockerVolumeConfiguration :: (Maybe DockerVolumeConfiguration
 -> f (Maybe DockerVolumeConfiguration))
-> Volume -> f Volume
volume_dockerVolumeConfiguration = (Volume -> Maybe DockerVolumeConfiguration)
-> (Volume -> Maybe DockerVolumeConfiguration -> Volume)
-> Lens
     Volume
     Volume
     (Maybe DockerVolumeConfiguration)
     (Maybe DockerVolumeConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe DockerVolumeConfiguration
dockerVolumeConfiguration :: Maybe DockerVolumeConfiguration
$sel:dockerVolumeConfiguration:Volume' :: Volume -> Maybe DockerVolumeConfiguration
dockerVolumeConfiguration} -> Maybe DockerVolumeConfiguration
dockerVolumeConfiguration) (\s :: Volume
s@Volume' {} Maybe DockerVolumeConfiguration
a -> Volume
s {$sel:dockerVolumeConfiguration:Volume' :: Maybe DockerVolumeConfiguration
dockerVolumeConfiguration = Maybe DockerVolumeConfiguration
a} :: Volume)

-- | This parameter is specified when you are using Amazon FSx for Windows
-- File Server file system for task storage.
volume_fsxWindowsFileServerVolumeConfiguration :: Lens.Lens' Volume (Prelude.Maybe FSxWindowsFileServerVolumeConfiguration)
volume_fsxWindowsFileServerVolumeConfiguration :: (Maybe FSxWindowsFileServerVolumeConfiguration
 -> f (Maybe FSxWindowsFileServerVolumeConfiguration))
-> Volume -> f Volume
volume_fsxWindowsFileServerVolumeConfiguration = (Volume -> Maybe FSxWindowsFileServerVolumeConfiguration)
-> (Volume
    -> Maybe FSxWindowsFileServerVolumeConfiguration -> Volume)
-> Lens
     Volume
     Volume
     (Maybe FSxWindowsFileServerVolumeConfiguration)
     (Maybe FSxWindowsFileServerVolumeConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration :: Maybe FSxWindowsFileServerVolumeConfiguration
$sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Volume -> Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration} -> Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration) (\s :: Volume
s@Volume' {} Maybe FSxWindowsFileServerVolumeConfiguration
a -> Volume
s {$sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration = Maybe FSxWindowsFileServerVolumeConfiguration
a} :: Volume)

-- | The name of the volume. Up to 255 letters (uppercase and lowercase),
-- numbers, underscores, and hyphens are allowed. This name is referenced
-- in the @sourceVolume@ parameter of container definition @mountPoints@.
volume_name :: Lens.Lens' Volume (Prelude.Maybe Prelude.Text)
volume_name :: (Maybe Text -> f (Maybe Text)) -> Volume -> f Volume
volume_name = (Volume -> Maybe Text)
-> (Volume -> Maybe Text -> Volume)
-> Lens Volume Volume (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe Text
name :: Maybe Text
$sel:name:Volume' :: Volume -> Maybe Text
name} -> Maybe Text
name) (\s :: Volume
s@Volume' {} Maybe Text
a -> Volume
s {$sel:name:Volume' :: Maybe Text
name = Maybe Text
a} :: Volume)

-- | This parameter is specified when you are using an Amazon Elastic File
-- System file system for task storage.
volume_efsVolumeConfiguration :: Lens.Lens' Volume (Prelude.Maybe EFSVolumeConfiguration)
volume_efsVolumeConfiguration :: (Maybe EFSVolumeConfiguration -> f (Maybe EFSVolumeConfiguration))
-> Volume -> f Volume
volume_efsVolumeConfiguration = (Volume -> Maybe EFSVolumeConfiguration)
-> (Volume -> Maybe EFSVolumeConfiguration -> Volume)
-> Lens
     Volume
     Volume
     (Maybe EFSVolumeConfiguration)
     (Maybe EFSVolumeConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe EFSVolumeConfiguration
efsVolumeConfiguration :: Maybe EFSVolumeConfiguration
$sel:efsVolumeConfiguration:Volume' :: Volume -> Maybe EFSVolumeConfiguration
efsVolumeConfiguration} -> Maybe EFSVolumeConfiguration
efsVolumeConfiguration) (\s :: Volume
s@Volume' {} Maybe EFSVolumeConfiguration
a -> Volume
s {$sel:efsVolumeConfiguration:Volume' :: Maybe EFSVolumeConfiguration
efsVolumeConfiguration = Maybe EFSVolumeConfiguration
a} :: Volume)

-- | This parameter is specified when you are using bind mount host volumes.
-- The contents of the @host@ parameter determine whether your bind mount
-- host volume persists on the host container instance and where it is
-- stored. If the @host@ parameter is empty, then the Docker daemon assigns
-- a host path for your data volume. However, the data is not guaranteed to
-- persist after the containers associated with it stop running.
--
-- Windows containers can mount whole directories on the same drive as
-- @$env:ProgramData@. Windows containers cannot mount directories on a
-- different drive, and mount point cannot be across drives. For example,
-- you can mount @C:\\my\\path:C:\\my\\path@ and @D:\\:D:\\@, but not
-- @D:\\my\\path:C:\\my\\path@ or @D:\\:C:\\my\\path@.
volume_host :: Lens.Lens' Volume (Prelude.Maybe HostVolumeProperties)
volume_host :: (Maybe HostVolumeProperties -> f (Maybe HostVolumeProperties))
-> Volume -> f Volume
volume_host = (Volume -> Maybe HostVolumeProperties)
-> (Volume -> Maybe HostVolumeProperties -> Volume)
-> Lens
     Volume
     Volume
     (Maybe HostVolumeProperties)
     (Maybe HostVolumeProperties)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe HostVolumeProperties
host :: Maybe HostVolumeProperties
$sel:host:Volume' :: Volume -> Maybe HostVolumeProperties
host} -> Maybe HostVolumeProperties
host) (\s :: Volume
s@Volume' {} Maybe HostVolumeProperties
a -> Volume
s {$sel:host:Volume' :: Maybe HostVolumeProperties
host = Maybe HostVolumeProperties
a} :: Volume)

instance Core.FromJSON Volume where
  parseJSON :: Value -> Parser Volume
parseJSON =
    String -> (Object -> Parser Volume) -> Value -> Parser Volume
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Volume"
      ( \Object
x ->
          Maybe DockerVolumeConfiguration
-> Maybe FSxWindowsFileServerVolumeConfiguration
-> Maybe Text
-> Maybe EFSVolumeConfiguration
-> Maybe HostVolumeProperties
-> Volume
Volume'
            (Maybe DockerVolumeConfiguration
 -> Maybe FSxWindowsFileServerVolumeConfiguration
 -> Maybe Text
 -> Maybe EFSVolumeConfiguration
 -> Maybe HostVolumeProperties
 -> Volume)
-> Parser (Maybe DockerVolumeConfiguration)
-> Parser
     (Maybe FSxWindowsFileServerVolumeConfiguration
      -> Maybe Text
      -> Maybe EFSVolumeConfiguration
      -> Maybe HostVolumeProperties
      -> Volume)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe DockerVolumeConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"dockerVolumeConfiguration")
            Parser
  (Maybe FSxWindowsFileServerVolumeConfiguration
   -> Maybe Text
   -> Maybe EFSVolumeConfiguration
   -> Maybe HostVolumeProperties
   -> Volume)
-> Parser (Maybe FSxWindowsFileServerVolumeConfiguration)
-> Parser
     (Maybe Text
      -> Maybe EFSVolumeConfiguration
      -> Maybe HostVolumeProperties
      -> Volume)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            Object
-> Text -> Parser (Maybe FSxWindowsFileServerVolumeConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"fsxWindowsFileServerVolumeConfiguration"
                        )
            Parser
  (Maybe Text
   -> Maybe EFSVolumeConfiguration
   -> Maybe HostVolumeProperties
   -> Volume)
-> Parser (Maybe Text)
-> Parser
     (Maybe EFSVolumeConfiguration
      -> Maybe HostVolumeProperties -> Volume)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"name")
            Parser
  (Maybe EFSVolumeConfiguration
   -> Maybe HostVolumeProperties -> Volume)
-> Parser (Maybe EFSVolumeConfiguration)
-> Parser (Maybe HostVolumeProperties -> Volume)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe EFSVolumeConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"efsVolumeConfiguration")
            Parser (Maybe HostVolumeProperties -> Volume)
-> Parser (Maybe HostVolumeProperties) -> Parser Volume
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HostVolumeProperties)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"host")
      )

instance Prelude.Hashable Volume

instance Prelude.NFData Volume

instance Core.ToJSON Volume where
  toJSON :: Volume -> Value
toJSON Volume' {Maybe Text
Maybe EFSVolumeConfiguration
Maybe FSxWindowsFileServerVolumeConfiguration
Maybe HostVolumeProperties
Maybe DockerVolumeConfiguration
host :: Maybe HostVolumeProperties
efsVolumeConfiguration :: Maybe EFSVolumeConfiguration
name :: Maybe Text
fsxWindowsFileServerVolumeConfiguration :: Maybe FSxWindowsFileServerVolumeConfiguration
dockerVolumeConfiguration :: Maybe DockerVolumeConfiguration
$sel:host:Volume' :: Volume -> Maybe HostVolumeProperties
$sel:efsVolumeConfiguration:Volume' :: Volume -> Maybe EFSVolumeConfiguration
$sel:name:Volume' :: Volume -> Maybe Text
$sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Volume -> Maybe FSxWindowsFileServerVolumeConfiguration
$sel:dockerVolumeConfiguration:Volume' :: Volume -> Maybe DockerVolumeConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"dockerVolumeConfiguration" Text -> DockerVolumeConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DockerVolumeConfiguration -> Pair)
-> Maybe DockerVolumeConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DockerVolumeConfiguration
dockerVolumeConfiguration,
            (Text
"fsxWindowsFileServerVolumeConfiguration" Text -> FSxWindowsFileServerVolumeConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (FSxWindowsFileServerVolumeConfiguration -> Pair)
-> Maybe FSxWindowsFileServerVolumeConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration,
            (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Text
"efsVolumeConfiguration" Text -> EFSVolumeConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (EFSVolumeConfiguration -> Pair)
-> Maybe EFSVolumeConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EFSVolumeConfiguration
efsVolumeConfiguration,
            (Text
"host" Text -> HostVolumeProperties -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HostVolumeProperties -> Pair)
-> Maybe HostVolumeProperties -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HostVolumeProperties
host
          ]
      )