{-# 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-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.Volume 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.DockerVolumeConfiguration
import Amazonka.ECS.Types.EFSVolumeConfiguration
import Amazonka.ECS.Types.FSxWindowsFileServerVolumeConfiguration
import Amazonka.ECS.Types.HostVolumeProperties
import qualified Amazonka.Prelude as Prelude

-- | A data volume that\'s 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 use Docker volumes.
    --
    -- Windows containers only support the use of the @local@ driver. To use
    -- bind mounts, specify the @host@ parameter instead.
    --
    -- Docker volumes aren\'t supported by tasks run on Fargate.
    Volume -> Maybe DockerVolumeConfiguration
dockerVolumeConfiguration :: Prelude.Maybe DockerVolumeConfiguration,
    -- | This parameter is specified when you use an Amazon Elastic File System
    -- file system for task storage.
    Volume -> Maybe EFSVolumeConfiguration
efsVolumeConfiguration :: Prelude.Maybe EFSVolumeConfiguration,
    -- | This parameter is specified when you use Amazon FSx for Windows File
    -- Server file system for task storage.
    Volume -> Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration :: Prelude.Maybe FSxWindowsFileServerVolumeConfiguration,
    -- | This parameter is specified when you use 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\'s stored.
    -- If the @host@ parameter is empty, then the Docker daemon assigns a host
    -- path for your data volume. However, the data isn\'t guaranteed to
    -- persist after the containers that are associated with it stop running.
    --
    -- Windows containers can mount whole directories on the same drive as
    -- @$env:ProgramData@. Windows containers can\'t mount directories on a
    -- different drive, and mount point can\'t 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,
    -- | 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
  }
  deriving (Volume -> Volume -> Bool
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]
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
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. 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 use Docker volumes.
--
-- Windows containers only support the use of the @local@ driver. To use
-- bind mounts, specify the @host@ parameter instead.
--
-- Docker volumes aren\'t supported by tasks run on Fargate.
--
-- 'efsVolumeConfiguration', 'volume_efsVolumeConfiguration' - This parameter is specified when you use an Amazon Elastic File System
-- file system for task storage.
--
-- 'fsxWindowsFileServerVolumeConfiguration', 'volume_fsxWindowsFileServerVolumeConfiguration' - This parameter is specified when you use Amazon FSx for Windows File
-- Server file system for task storage.
--
-- 'host', 'volume_host' - This parameter is specified when you use 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\'s stored.
-- If the @host@ parameter is empty, then the Docker daemon assigns a host
-- path for your data volume. However, the data isn\'t guaranteed to
-- persist after the containers that are associated with it stop running.
--
-- Windows containers can mount whole directories on the same drive as
-- @$env:ProgramData@. Windows containers can\'t mount directories on a
-- different drive, and mount point can\'t 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@.
--
-- '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@.
newVolume ::
  Volume
newVolume :: Volume
newVolume =
  Volume'
    { $sel:dockerVolumeConfiguration:Volume' :: Maybe DockerVolumeConfiguration
dockerVolumeConfiguration =
        forall a. Maybe a
Prelude.Nothing,
      $sel:efsVolumeConfiguration:Volume' :: Maybe EFSVolumeConfiguration
efsVolumeConfiguration = forall a. Maybe a
Prelude.Nothing,
      $sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration =
        forall a. Maybe a
Prelude.Nothing,
      $sel:host:Volume' :: Maybe HostVolumeProperties
host = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Volume' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing
    }

-- | This parameter is specified when you use Docker volumes.
--
-- Windows containers only support the use of the @local@ driver. To use
-- bind mounts, specify the @host@ parameter instead.
--
-- Docker volumes aren\'t supported by tasks run on Fargate.
volume_dockerVolumeConfiguration :: Lens.Lens' Volume (Prelude.Maybe DockerVolumeConfiguration)
volume_dockerVolumeConfiguration :: Lens' Volume (Maybe DockerVolumeConfiguration)
volume_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 use an Amazon Elastic File System
-- file system for task storage.
volume_efsVolumeConfiguration :: Lens.Lens' Volume (Prelude.Maybe EFSVolumeConfiguration)
volume_efsVolumeConfiguration :: Lens' Volume (Maybe EFSVolumeConfiguration)
volume_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 use Amazon FSx for Windows File
-- Server file system for task storage.
volume_fsxWindowsFileServerVolumeConfiguration :: Lens.Lens' Volume (Prelude.Maybe FSxWindowsFileServerVolumeConfiguration)
volume_fsxWindowsFileServerVolumeConfiguration :: Lens' Volume (Maybe FSxWindowsFileServerVolumeConfiguration)
volume_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)

-- | This parameter is specified when you use 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\'s stored.
-- If the @host@ parameter is empty, then the Docker daemon assigns a host
-- path for your data volume. However, the data isn\'t guaranteed to
-- persist after the containers that are associated with it stop running.
--
-- Windows containers can mount whole directories on the same drive as
-- @$env:ProgramData@. Windows containers can\'t mount directories on a
-- different drive, and mount point can\'t 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 :: Lens' Volume (Maybe HostVolumeProperties)
volume_host = 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)

-- | 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 :: Lens' Volume (Maybe Text)
volume_name = 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)

instance Data.FromJSON Volume where
  parseJSON :: Value -> Parser Volume
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Volume"
      ( \Object
x ->
          Maybe DockerVolumeConfiguration
-> Maybe EFSVolumeConfiguration
-> Maybe FSxWindowsFileServerVolumeConfiguration
-> Maybe HostVolumeProperties
-> Maybe Text
-> Volume
Volume'
            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
"dockerVolumeConfiguration")
            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
"efsVolumeConfiguration")
            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
"fsxWindowsFileServerVolumeConfiguration"
                        )
            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
"host")
            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
"name")
      )

instance Prelude.Hashable Volume where
  hashWithSalt :: Int -> Volume -> Int
hashWithSalt Int
_salt Volume' {Maybe Text
Maybe EFSVolumeConfiguration
Maybe FSxWindowsFileServerVolumeConfiguration
Maybe HostVolumeProperties
Maybe DockerVolumeConfiguration
name :: Maybe Text
host :: Maybe HostVolumeProperties
fsxWindowsFileServerVolumeConfiguration :: Maybe FSxWindowsFileServerVolumeConfiguration
efsVolumeConfiguration :: Maybe EFSVolumeConfiguration
dockerVolumeConfiguration :: Maybe DockerVolumeConfiguration
$sel:name:Volume' :: Volume -> Maybe Text
$sel:host:Volume' :: Volume -> Maybe HostVolumeProperties
$sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Volume -> Maybe FSxWindowsFileServerVolumeConfiguration
$sel:efsVolumeConfiguration:Volume' :: Volume -> Maybe EFSVolumeConfiguration
$sel:dockerVolumeConfiguration:Volume' :: Volume -> Maybe DockerVolumeConfiguration
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DockerVolumeConfiguration
dockerVolumeConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EFSVolumeConfiguration
efsVolumeConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe HostVolumeProperties
host
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name

instance Prelude.NFData Volume where
  rnf :: Volume -> ()
rnf Volume' {Maybe Text
Maybe EFSVolumeConfiguration
Maybe FSxWindowsFileServerVolumeConfiguration
Maybe HostVolumeProperties
Maybe DockerVolumeConfiguration
name :: Maybe Text
host :: Maybe HostVolumeProperties
fsxWindowsFileServerVolumeConfiguration :: Maybe FSxWindowsFileServerVolumeConfiguration
efsVolumeConfiguration :: Maybe EFSVolumeConfiguration
dockerVolumeConfiguration :: Maybe DockerVolumeConfiguration
$sel:name:Volume' :: Volume -> Maybe Text
$sel:host:Volume' :: Volume -> Maybe HostVolumeProperties
$sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Volume -> Maybe FSxWindowsFileServerVolumeConfiguration
$sel:efsVolumeConfiguration:Volume' :: Volume -> Maybe EFSVolumeConfiguration
$sel:dockerVolumeConfiguration:Volume' :: Volume -> Maybe DockerVolumeConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DockerVolumeConfiguration
dockerVolumeConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EFSVolumeConfiguration
efsVolumeConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe HostVolumeProperties
host
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name

instance Data.ToJSON Volume where
  toJSON :: Volume -> Value
toJSON Volume' {Maybe Text
Maybe EFSVolumeConfiguration
Maybe FSxWindowsFileServerVolumeConfiguration
Maybe HostVolumeProperties
Maybe DockerVolumeConfiguration
name :: Maybe Text
host :: Maybe HostVolumeProperties
fsxWindowsFileServerVolumeConfiguration :: Maybe FSxWindowsFileServerVolumeConfiguration
efsVolumeConfiguration :: Maybe EFSVolumeConfiguration
dockerVolumeConfiguration :: Maybe DockerVolumeConfiguration
$sel:name:Volume' :: Volume -> Maybe Text
$sel:host:Volume' :: Volume -> Maybe HostVolumeProperties
$sel:fsxWindowsFileServerVolumeConfiguration:Volume' :: Volume -> Maybe FSxWindowsFileServerVolumeConfiguration
$sel:efsVolumeConfiguration:Volume' :: Volume -> Maybe EFSVolumeConfiguration
$sel:dockerVolumeConfiguration:Volume' :: Volume -> Maybe DockerVolumeConfiguration
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"dockerVolumeConfiguration" 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 DockerVolumeConfiguration
dockerVolumeConfiguration,
            (Key
"efsVolumeConfiguration" 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 EFSVolumeConfiguration
efsVolumeConfiguration,
            (Key
"fsxWindowsFileServerVolumeConfiguration" 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 FSxWindowsFileServerVolumeConfiguration
fsxWindowsFileServerVolumeConfiguration,
            (Key
"host" 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 HostVolumeProperties
host,
            (Key
"name" 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
name
          ]
      )