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

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

-- | This structure specifies the VPC subnets and security groups for the
-- task, and whether a public IP address is to be used. This structure is
-- relevant only for ECS tasks that use the @awsvpc@ network mode.
--
-- /See:/ 'newAwsVpcConfiguration' smart constructor.
data AwsVpcConfiguration = AwsVpcConfiguration'
  { -- | Specifies the security groups associated with the task. These security
    -- groups must all be in the same VPC. You can specify as many as five
    -- security groups. If you do not specify a security group, the default
    -- security group for the VPC is used.
    AwsVpcConfiguration -> Maybe [Text]
securityGroups :: Prelude.Maybe [Prelude.Text],
    -- | Specifies whether the task\'s elastic network interface receives a
    -- public IP address. You can specify @ENABLED@ only when @LaunchType@ in
    -- @EcsParameters@ is set to @FARGATE@.
    AwsVpcConfiguration -> Maybe AssignPublicIp
assignPublicIp :: Prelude.Maybe AssignPublicIp,
    -- | Specifies the subnets associated with the task. These subnets must all
    -- be in the same VPC. You can specify as many as 16 subnets.
    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' - Specifies the security groups associated with the task. These security
-- groups must all be in the same VPC. You can specify as many as five
-- security groups. If you do not specify a security group, the default
-- security group for the VPC is used.
--
-- 'assignPublicIp', 'awsVpcConfiguration_assignPublicIp' - Specifies whether the task\'s elastic network interface receives a
-- public IP address. You can specify @ENABLED@ only when @LaunchType@ in
-- @EcsParameters@ is set to @FARGATE@.
--
-- 'subnets', 'awsVpcConfiguration_subnets' - Specifies the subnets associated with the task. These subnets must all
-- be in the same VPC. You can specify as many as 16 subnets.
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
    }

-- | Specifies the security groups associated with the task. These security
-- groups must all be in the same VPC. You can specify as many as five
-- security groups. If you do not specify a security group, the default
-- security group for the VPC is used.
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

-- | Specifies whether the task\'s elastic network interface receives a
-- public IP address. You can specify @ENABLED@ only when @LaunchType@ in
-- @EcsParameters@ is set to @FARGATE@.
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)

-- | Specifies the subnets associated with the task. These subnets must all
-- be in the same VPC. You can specify as many as 16 subnets.
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)
          ]
      )