{-# 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.DataSync.Types.Ec2Config
-- 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.DataSync.Types.Ec2Config where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The subnet and security groups that DataSync uses to access your Amazon
-- EFS file system.
--
-- /See:/ 'newEc2Config' smart constructor.
data Ec2Config = Ec2Config'
  { -- | Specifies the ARN of a subnet where DataSync creates the
    -- <https://docs.aws.amazon.com/datasync/latest/userguide/datasync-network.html#required-network-interfaces network interfaces>
    -- for managing traffic during your transfer.
    --
    -- The subnet must be located:
    --
    -- -   In the same virtual private cloud (VPC) as the Amazon EFS file
    --     system.
    --
    -- -   In the same Availability Zone as at least one mount target for the
    --     Amazon EFS file system.
    --
    -- You don\'t need to specify a subnet that includes a file system mount
    -- target.
    Ec2Config -> Text
subnetArn :: Prelude.Text,
    -- | Specifies the Amazon Resource Names (ARNs) of the security groups
    -- associated with an Amazon EFS file system\'s mount target.
    Ec2Config -> NonEmpty Text
securityGroupArns :: Prelude.NonEmpty Prelude.Text
  }
  deriving (Ec2Config -> Ec2Config -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ec2Config -> Ec2Config -> Bool
$c/= :: Ec2Config -> Ec2Config -> Bool
== :: Ec2Config -> Ec2Config -> Bool
$c== :: Ec2Config -> Ec2Config -> Bool
Prelude.Eq, ReadPrec [Ec2Config]
ReadPrec Ec2Config
Int -> ReadS Ec2Config
ReadS [Ec2Config]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ec2Config]
$creadListPrec :: ReadPrec [Ec2Config]
readPrec :: ReadPrec Ec2Config
$creadPrec :: ReadPrec Ec2Config
readList :: ReadS [Ec2Config]
$creadList :: ReadS [Ec2Config]
readsPrec :: Int -> ReadS Ec2Config
$creadsPrec :: Int -> ReadS Ec2Config
Prelude.Read, Int -> Ec2Config -> ShowS
[Ec2Config] -> ShowS
Ec2Config -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ec2Config] -> ShowS
$cshowList :: [Ec2Config] -> ShowS
show :: Ec2Config -> String
$cshow :: Ec2Config -> String
showsPrec :: Int -> Ec2Config -> ShowS
$cshowsPrec :: Int -> Ec2Config -> ShowS
Prelude.Show, forall x. Rep Ec2Config x -> Ec2Config
forall x. Ec2Config -> Rep Ec2Config x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Ec2Config x -> Ec2Config
$cfrom :: forall x. Ec2Config -> Rep Ec2Config x
Prelude.Generic)

-- |
-- Create a value of 'Ec2Config' 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:
--
-- 'subnetArn', 'ec2Config_subnetArn' - Specifies the ARN of a subnet where DataSync creates the
-- <https://docs.aws.amazon.com/datasync/latest/userguide/datasync-network.html#required-network-interfaces network interfaces>
-- for managing traffic during your transfer.
--
-- The subnet must be located:
--
-- -   In the same virtual private cloud (VPC) as the Amazon EFS file
--     system.
--
-- -   In the same Availability Zone as at least one mount target for the
--     Amazon EFS file system.
--
-- You don\'t need to specify a subnet that includes a file system mount
-- target.
--
-- 'securityGroupArns', 'ec2Config_securityGroupArns' - Specifies the Amazon Resource Names (ARNs) of the security groups
-- associated with an Amazon EFS file system\'s mount target.
newEc2Config ::
  -- | 'subnetArn'
  Prelude.Text ->
  -- | 'securityGroupArns'
  Prelude.NonEmpty Prelude.Text ->
  Ec2Config
newEc2Config :: Text -> NonEmpty Text -> Ec2Config
newEc2Config Text
pSubnetArn_ NonEmpty Text
pSecurityGroupArns_ =
  Ec2Config'
    { $sel:subnetArn:Ec2Config' :: Text
subnetArn = Text
pSubnetArn_,
      $sel:securityGroupArns:Ec2Config' :: NonEmpty Text
securityGroupArns =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pSecurityGroupArns_
    }

-- | Specifies the ARN of a subnet where DataSync creates the
-- <https://docs.aws.amazon.com/datasync/latest/userguide/datasync-network.html#required-network-interfaces network interfaces>
-- for managing traffic during your transfer.
--
-- The subnet must be located:
--
-- -   In the same virtual private cloud (VPC) as the Amazon EFS file
--     system.
--
-- -   In the same Availability Zone as at least one mount target for the
--     Amazon EFS file system.
--
-- You don\'t need to specify a subnet that includes a file system mount
-- target.
ec2Config_subnetArn :: Lens.Lens' Ec2Config Prelude.Text
ec2Config_subnetArn :: Lens' Ec2Config Text
ec2Config_subnetArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ec2Config' {Text
subnetArn :: Text
$sel:subnetArn:Ec2Config' :: Ec2Config -> Text
subnetArn} -> Text
subnetArn) (\s :: Ec2Config
s@Ec2Config' {} Text
a -> Ec2Config
s {$sel:subnetArn:Ec2Config' :: Text
subnetArn = Text
a} :: Ec2Config)

-- | Specifies the Amazon Resource Names (ARNs) of the security groups
-- associated with an Amazon EFS file system\'s mount target.
ec2Config_securityGroupArns :: Lens.Lens' Ec2Config (Prelude.NonEmpty Prelude.Text)
ec2Config_securityGroupArns :: Lens' Ec2Config (NonEmpty Text)
ec2Config_securityGroupArns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ec2Config' {NonEmpty Text
securityGroupArns :: NonEmpty Text
$sel:securityGroupArns:Ec2Config' :: Ec2Config -> NonEmpty Text
securityGroupArns} -> NonEmpty Text
securityGroupArns) (\s :: Ec2Config
s@Ec2Config' {} NonEmpty Text
a -> Ec2Config
s {$sel:securityGroupArns:Ec2Config' :: NonEmpty Text
securityGroupArns = NonEmpty Text
a} :: Ec2Config) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON Ec2Config where
  parseJSON :: Value -> Parser Ec2Config
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Ec2Config"
      ( \Object
x ->
          Text -> NonEmpty Text -> Ec2Config
Ec2Config'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"SubnetArn")
            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
"SecurityGroupArns")
      )

instance Prelude.Hashable Ec2Config where
  hashWithSalt :: Int -> Ec2Config -> Int
hashWithSalt Int
_salt Ec2Config' {NonEmpty Text
Text
securityGroupArns :: NonEmpty Text
subnetArn :: Text
$sel:securityGroupArns:Ec2Config' :: Ec2Config -> NonEmpty Text
$sel:subnetArn:Ec2Config' :: Ec2Config -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
subnetArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
securityGroupArns

instance Prelude.NFData Ec2Config where
  rnf :: Ec2Config -> ()
rnf Ec2Config' {NonEmpty Text
Text
securityGroupArns :: NonEmpty Text
subnetArn :: Text
$sel:securityGroupArns:Ec2Config' :: Ec2Config -> NonEmpty Text
$sel:subnetArn:Ec2Config' :: Ec2Config -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
subnetArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
securityGroupArns

instance Data.ToJSON Ec2Config where
  toJSON :: Ec2Config -> Value
toJSON Ec2Config' {NonEmpty Text
Text
securityGroupArns :: NonEmpty Text
subnetArn :: Text
$sel:securityGroupArns:Ec2Config' :: Ec2Config -> NonEmpty Text
$sel:subnetArn:Ec2Config' :: Ec2Config -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"SubnetArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
subnetArn),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"SecurityGroupArns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
securityGroupArns)
          ]
      )