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

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

-- | An object representing the networking details for a task or service.
--
-- /See:/ 'newAwsVpcConfiguration' smart constructor.
data AwsVpcConfiguration = AwsVpcConfiguration'
  { -- | The IDs of the security groups associated with the task or service. If
    -- you do not specify a security group, the default security group for the
    -- VPC is used. There is a limit of 5 security groups that can be specified
    -- per @AwsVpcConfiguration@.
    --
    -- All specified security groups must be from the same VPC.
    AwsVpcConfiguration -> Maybe [Text]
securityGroups :: Prelude.Maybe [Prelude.Text],
    -- | Whether the task\'s elastic network interface receives a public IP
    -- address. The default value is @DISABLED@.
    AwsVpcConfiguration -> Maybe AssignPublicIp
assignPublicIp :: Prelude.Maybe AssignPublicIp,
    -- | The IDs of the subnets associated with the task or service. There is a
    -- limit of 16 subnets that can be specified per @AwsVpcConfiguration@.
    --
    -- All specified subnets must be from the same VPC.
    AwsVpcConfiguration -> [Text]
subnets :: [Prelude.Text]
  }
  deriving (AwsVpcConfiguration -> AwsVpcConfiguration -> Bool
(AwsVpcConfiguration -> AwsVpcConfiguration -> Bool)
-> (AwsVpcConfiguration -> AwsVpcConfiguration -> Bool)
-> Eq AwsVpcConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AwsVpcConfiguration -> AwsVpcConfiguration -> Bool
$c/= :: AwsVpcConfiguration -> AwsVpcConfiguration -> Bool
== :: AwsVpcConfiguration -> AwsVpcConfiguration -> Bool
$c== :: AwsVpcConfiguration -> AwsVpcConfiguration -> Bool
Prelude.Eq, ReadPrec [AwsVpcConfiguration]
ReadPrec AwsVpcConfiguration
Int -> ReadS AwsVpcConfiguration
ReadS [AwsVpcConfiguration]
(Int -> ReadS AwsVpcConfiguration)
-> ReadS [AwsVpcConfiguration]
-> ReadPrec AwsVpcConfiguration
-> ReadPrec [AwsVpcConfiguration]
-> Read AwsVpcConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AwsVpcConfiguration]
$creadListPrec :: ReadPrec [AwsVpcConfiguration]
readPrec :: ReadPrec AwsVpcConfiguration
$creadPrec :: ReadPrec AwsVpcConfiguration
readList :: ReadS [AwsVpcConfiguration]
$creadList :: ReadS [AwsVpcConfiguration]
readsPrec :: Int -> ReadS AwsVpcConfiguration
$creadsPrec :: Int -> ReadS AwsVpcConfiguration
Prelude.Read, Int -> AwsVpcConfiguration -> ShowS
[AwsVpcConfiguration] -> ShowS
AwsVpcConfiguration -> String
(Int -> AwsVpcConfiguration -> ShowS)
-> (AwsVpcConfiguration -> String)
-> ([AwsVpcConfiguration] -> ShowS)
-> Show AwsVpcConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AwsVpcConfiguration] -> ShowS
$cshowList :: [AwsVpcConfiguration] -> ShowS
show :: AwsVpcConfiguration -> String
$cshow :: AwsVpcConfiguration -> String
showsPrec :: Int -> AwsVpcConfiguration -> ShowS
$cshowsPrec :: Int -> AwsVpcConfiguration -> ShowS
Prelude.Show, (forall x. AwsVpcConfiguration -> Rep AwsVpcConfiguration x)
-> (forall x. Rep AwsVpcConfiguration x -> AwsVpcConfiguration)
-> Generic AwsVpcConfiguration
forall x. Rep AwsVpcConfiguration x -> AwsVpcConfiguration
forall x. AwsVpcConfiguration -> Rep AwsVpcConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AwsVpcConfiguration x -> AwsVpcConfiguration
$cfrom :: forall x. AwsVpcConfiguration -> Rep AwsVpcConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'AwsVpcConfiguration' 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:
--
-- 'securityGroups', 'awsVpcConfiguration_securityGroups' - The IDs of the security groups associated with the task or service. If
-- you do not specify a security group, the default security group for the
-- VPC is used. There is a limit of 5 security groups that can be specified
-- per @AwsVpcConfiguration@.
--
-- All specified security groups must be from the same VPC.
--
-- 'assignPublicIp', 'awsVpcConfiguration_assignPublicIp' - Whether the task\'s elastic network interface receives a public IP
-- address. The default value is @DISABLED@.
--
-- 'subnets', 'awsVpcConfiguration_subnets' - The IDs of the subnets associated with the task or service. There is a
-- limit of 16 subnets that can be specified per @AwsVpcConfiguration@.
--
-- All specified subnets must be from the same VPC.
newAwsVpcConfiguration ::
  AwsVpcConfiguration
newAwsVpcConfiguration :: AwsVpcConfiguration
newAwsVpcConfiguration =
  AwsVpcConfiguration' :: Maybe [Text]
-> Maybe AssignPublicIp -> [Text] -> AwsVpcConfiguration
AwsVpcConfiguration'
    { $sel:securityGroups:AwsVpcConfiguration' :: Maybe [Text]
securityGroups =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:assignPublicIp:AwsVpcConfiguration' :: Maybe AssignPublicIp
assignPublicIp = Maybe AssignPublicIp
forall a. Maybe a
Prelude.Nothing,
      $sel:subnets:AwsVpcConfiguration' :: [Text]
subnets = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The IDs of the security groups associated with the task or service. If
-- you do not specify a security group, the default security group for the
-- VPC is used. There is a limit of 5 security groups that can be specified
-- per @AwsVpcConfiguration@.
--
-- All specified security groups must be from the same VPC.
awsVpcConfiguration_securityGroups :: Lens.Lens' AwsVpcConfiguration (Prelude.Maybe [Prelude.Text])
awsVpcConfiguration_securityGroups :: (Maybe [Text] -> f (Maybe [Text]))
-> AwsVpcConfiguration -> f AwsVpcConfiguration
awsVpcConfiguration_securityGroups = (AwsVpcConfiguration -> Maybe [Text])
-> (AwsVpcConfiguration -> Maybe [Text] -> AwsVpcConfiguration)
-> Lens
     AwsVpcConfiguration
     AwsVpcConfiguration
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AwsVpcConfiguration' {Maybe [Text]
securityGroups :: Maybe [Text]
$sel:securityGroups:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe [Text]
securityGroups} -> Maybe [Text]
securityGroups) (\s :: AwsVpcConfiguration
s@AwsVpcConfiguration' {} Maybe [Text]
a -> AwsVpcConfiguration
s {$sel:securityGroups:AwsVpcConfiguration' :: Maybe [Text]
securityGroups = Maybe [Text]
a} :: AwsVpcConfiguration) ((Maybe [Text] -> f (Maybe [Text]))
 -> AwsVpcConfiguration -> f AwsVpcConfiguration)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> AwsVpcConfiguration
-> f AwsVpcConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Whether the task\'s elastic network interface receives a public IP
-- address. The default value is @DISABLED@.
awsVpcConfiguration_assignPublicIp :: Lens.Lens' AwsVpcConfiguration (Prelude.Maybe AssignPublicIp)
awsVpcConfiguration_assignPublicIp :: (Maybe AssignPublicIp -> f (Maybe AssignPublicIp))
-> AwsVpcConfiguration -> f AwsVpcConfiguration
awsVpcConfiguration_assignPublicIp = (AwsVpcConfiguration -> Maybe AssignPublicIp)
-> (AwsVpcConfiguration
    -> Maybe AssignPublicIp -> AwsVpcConfiguration)
-> Lens
     AwsVpcConfiguration
     AwsVpcConfiguration
     (Maybe AssignPublicIp)
     (Maybe AssignPublicIp)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AwsVpcConfiguration' {Maybe AssignPublicIp
assignPublicIp :: Maybe AssignPublicIp
$sel:assignPublicIp:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe AssignPublicIp
assignPublicIp} -> Maybe AssignPublicIp
assignPublicIp) (\s :: AwsVpcConfiguration
s@AwsVpcConfiguration' {} Maybe AssignPublicIp
a -> AwsVpcConfiguration
s {$sel:assignPublicIp:AwsVpcConfiguration' :: Maybe AssignPublicIp
assignPublicIp = Maybe AssignPublicIp
a} :: AwsVpcConfiguration)

-- | The IDs of the subnets associated with the task or service. There is a
-- limit of 16 subnets that can be specified per @AwsVpcConfiguration@.
--
-- All specified subnets must be from the same VPC.
awsVpcConfiguration_subnets :: Lens.Lens' AwsVpcConfiguration [Prelude.Text]
awsVpcConfiguration_subnets :: ([Text] -> f [Text])
-> AwsVpcConfiguration -> f AwsVpcConfiguration
awsVpcConfiguration_subnets = (AwsVpcConfiguration -> [Text])
-> (AwsVpcConfiguration -> [Text] -> AwsVpcConfiguration)
-> Lens AwsVpcConfiguration AwsVpcConfiguration [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AwsVpcConfiguration' {[Text]
subnets :: [Text]
$sel:subnets:AwsVpcConfiguration' :: AwsVpcConfiguration -> [Text]
subnets} -> [Text]
subnets) (\s :: AwsVpcConfiguration
s@AwsVpcConfiguration' {} [Text]
a -> AwsVpcConfiguration
s {$sel:subnets:AwsVpcConfiguration' :: [Text]
subnets = [Text]
a} :: AwsVpcConfiguration) (([Text] -> f [Text])
 -> AwsVpcConfiguration -> f AwsVpcConfiguration)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AwsVpcConfiguration
-> f AwsVpcConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON AwsVpcConfiguration where
  parseJSON :: Value -> Parser AwsVpcConfiguration
parseJSON =
    String
-> (Object -> Parser AwsVpcConfiguration)
-> Value
-> Parser AwsVpcConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AwsVpcConfiguration"
      ( \Object
x ->
          Maybe [Text]
-> Maybe AssignPublicIp -> [Text] -> AwsVpcConfiguration
AwsVpcConfiguration'
            (Maybe [Text]
 -> Maybe AssignPublicIp -> [Text] -> AwsVpcConfiguration)
-> Parser (Maybe [Text])
-> Parser (Maybe AssignPublicIp -> [Text] -> AwsVpcConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"securityGroups" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe AssignPublicIp -> [Text] -> AwsVpcConfiguration)
-> Parser (Maybe AssignPublicIp)
-> Parser ([Text] -> AwsVpcConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AssignPublicIp)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"assignPublicIp")
            Parser ([Text] -> AwsVpcConfiguration)
-> Parser [Text] -> Parser AwsVpcConfiguration
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
"subnets" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable AwsVpcConfiguration

instance Prelude.NFData AwsVpcConfiguration

instance Core.ToJSON AwsVpcConfiguration where
  toJSON :: AwsVpcConfiguration -> Value
toJSON AwsVpcConfiguration' {[Text]
Maybe [Text]
Maybe AssignPublicIp
subnets :: [Text]
assignPublicIp :: Maybe AssignPublicIp
securityGroups :: Maybe [Text]
$sel:subnets:AwsVpcConfiguration' :: AwsVpcConfiguration -> [Text]
$sel:assignPublicIp:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe AssignPublicIp
$sel:securityGroups:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"securityGroups" 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]
securityGroups,
            (Text
"assignPublicIp" Text -> AssignPublicIp -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AssignPublicIp -> Pair) -> Maybe AssignPublicIp -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AssignPublicIp
assignPublicIp,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"subnets" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
subnets)
          ]
      )