{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 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 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 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
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]
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
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. 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:
--
-- '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@.
--
-- '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.
--
-- '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'
    { $sel:assignPublicIp:AwsVpcConfiguration' :: Maybe AssignPublicIp
assignPublicIp =
        forall a. Maybe a
Prelude.Nothing,
      $sel:securityGroups:AwsVpcConfiguration' :: Maybe [Text]
securityGroups = forall a. Maybe a
Prelude.Nothing,
      $sel:subnets:AwsVpcConfiguration' :: [Text]
subnets = forall a. Monoid a => a
Prelude.mempty
    }

-- | 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 :: Lens' AwsVpcConfiguration (Maybe AssignPublicIp)
awsVpcConfiguration_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 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 :: Lens' AwsVpcConfiguration (Maybe [Text])
awsVpcConfiguration_securityGroups = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: Lens' AwsVpcConfiguration [Text]
awsVpcConfiguration_subnets = 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) 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 AwsVpcConfiguration where
  parseJSON :: Value -> Parser AwsVpcConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AwsVpcConfiguration"
      ( \Object
x ->
          Maybe AssignPublicIp
-> Maybe [Text] -> [Text] -> AwsVpcConfiguration
AwsVpcConfiguration'
            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
"AssignPublicIp")
            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
"SecurityGroups" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"Subnets" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable AwsVpcConfiguration where
  hashWithSalt :: Int -> AwsVpcConfiguration -> Int
hashWithSalt Int
_salt AwsVpcConfiguration' {[Text]
Maybe [Text]
Maybe AssignPublicIp
subnets :: [Text]
securityGroups :: Maybe [Text]
assignPublicIp :: Maybe AssignPublicIp
$sel:subnets:AwsVpcConfiguration' :: AwsVpcConfiguration -> [Text]
$sel:securityGroups:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe [Text]
$sel:assignPublicIp:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe AssignPublicIp
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AssignPublicIp
assignPublicIp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
securityGroups
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
subnets

instance Prelude.NFData AwsVpcConfiguration where
  rnf :: AwsVpcConfiguration -> ()
rnf AwsVpcConfiguration' {[Text]
Maybe [Text]
Maybe AssignPublicIp
subnets :: [Text]
securityGroups :: Maybe [Text]
assignPublicIp :: Maybe AssignPublicIp
$sel:subnets:AwsVpcConfiguration' :: AwsVpcConfiguration -> [Text]
$sel:securityGroups:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe [Text]
$sel:assignPublicIp:AwsVpcConfiguration' :: AwsVpcConfiguration -> Maybe AssignPublicIp
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AssignPublicIp
assignPublicIp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
securityGroups
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
subnets

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