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

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

-- | This structure specifies the network configuration for an ECS task.
--
-- /See:/ 'newNetworkConfiguration' smart constructor.
data NetworkConfiguration = NetworkConfiguration'
  { -- | Use this structure to specify 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.
    NetworkConfiguration -> Maybe AwsVpcConfiguration
awsvpcConfiguration :: Prelude.Maybe AwsVpcConfiguration
  }
  deriving (NetworkConfiguration -> NetworkConfiguration -> Bool
(NetworkConfiguration -> NetworkConfiguration -> Bool)
-> (NetworkConfiguration -> NetworkConfiguration -> Bool)
-> Eq NetworkConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetworkConfiguration -> NetworkConfiguration -> Bool
$c/= :: NetworkConfiguration -> NetworkConfiguration -> Bool
== :: NetworkConfiguration -> NetworkConfiguration -> Bool
$c== :: NetworkConfiguration -> NetworkConfiguration -> Bool
Prelude.Eq, ReadPrec [NetworkConfiguration]
ReadPrec NetworkConfiguration
Int -> ReadS NetworkConfiguration
ReadS [NetworkConfiguration]
(Int -> ReadS NetworkConfiguration)
-> ReadS [NetworkConfiguration]
-> ReadPrec NetworkConfiguration
-> ReadPrec [NetworkConfiguration]
-> Read NetworkConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NetworkConfiguration]
$creadListPrec :: ReadPrec [NetworkConfiguration]
readPrec :: ReadPrec NetworkConfiguration
$creadPrec :: ReadPrec NetworkConfiguration
readList :: ReadS [NetworkConfiguration]
$creadList :: ReadS [NetworkConfiguration]
readsPrec :: Int -> ReadS NetworkConfiguration
$creadsPrec :: Int -> ReadS NetworkConfiguration
Prelude.Read, Int -> NetworkConfiguration -> ShowS
[NetworkConfiguration] -> ShowS
NetworkConfiguration -> String
(Int -> NetworkConfiguration -> ShowS)
-> (NetworkConfiguration -> String)
-> ([NetworkConfiguration] -> ShowS)
-> Show NetworkConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetworkConfiguration] -> ShowS
$cshowList :: [NetworkConfiguration] -> ShowS
show :: NetworkConfiguration -> String
$cshow :: NetworkConfiguration -> String
showsPrec :: Int -> NetworkConfiguration -> ShowS
$cshowsPrec :: Int -> NetworkConfiguration -> ShowS
Prelude.Show, (forall x. NetworkConfiguration -> Rep NetworkConfiguration x)
-> (forall x. Rep NetworkConfiguration x -> NetworkConfiguration)
-> Generic NetworkConfiguration
forall x. Rep NetworkConfiguration x -> NetworkConfiguration
forall x. NetworkConfiguration -> Rep NetworkConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NetworkConfiguration x -> NetworkConfiguration
$cfrom :: forall x. NetworkConfiguration -> Rep NetworkConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'NetworkConfiguration' 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:
--
-- 'awsvpcConfiguration', 'networkConfiguration_awsvpcConfiguration' - Use this structure to specify 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.
newNetworkConfiguration ::
  NetworkConfiguration
newNetworkConfiguration :: NetworkConfiguration
newNetworkConfiguration =
  NetworkConfiguration' :: Maybe AwsVpcConfiguration -> NetworkConfiguration
NetworkConfiguration'
    { $sel:awsvpcConfiguration:NetworkConfiguration' :: Maybe AwsVpcConfiguration
awsvpcConfiguration =
        Maybe AwsVpcConfiguration
forall a. Maybe a
Prelude.Nothing
    }

-- | Use this structure to specify 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.
networkConfiguration_awsvpcConfiguration :: Lens.Lens' NetworkConfiguration (Prelude.Maybe AwsVpcConfiguration)
networkConfiguration_awsvpcConfiguration :: (Maybe AwsVpcConfiguration -> f (Maybe AwsVpcConfiguration))
-> NetworkConfiguration -> f NetworkConfiguration
networkConfiguration_awsvpcConfiguration = (NetworkConfiguration -> Maybe AwsVpcConfiguration)
-> (NetworkConfiguration
    -> Maybe AwsVpcConfiguration -> NetworkConfiguration)
-> Lens
     NetworkConfiguration
     NetworkConfiguration
     (Maybe AwsVpcConfiguration)
     (Maybe AwsVpcConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkConfiguration' {Maybe AwsVpcConfiguration
awsvpcConfiguration :: Maybe AwsVpcConfiguration
$sel:awsvpcConfiguration:NetworkConfiguration' :: NetworkConfiguration -> Maybe AwsVpcConfiguration
awsvpcConfiguration} -> Maybe AwsVpcConfiguration
awsvpcConfiguration) (\s :: NetworkConfiguration
s@NetworkConfiguration' {} Maybe AwsVpcConfiguration
a -> NetworkConfiguration
s {$sel:awsvpcConfiguration:NetworkConfiguration' :: Maybe AwsVpcConfiguration
awsvpcConfiguration = Maybe AwsVpcConfiguration
a} :: NetworkConfiguration)

instance Core.FromJSON NetworkConfiguration where
  parseJSON :: Value -> Parser NetworkConfiguration
parseJSON =
    String
-> (Object -> Parser NetworkConfiguration)
-> Value
-> Parser NetworkConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NetworkConfiguration"
      ( \Object
x ->
          Maybe AwsVpcConfiguration -> NetworkConfiguration
NetworkConfiguration'
            (Maybe AwsVpcConfiguration -> NetworkConfiguration)
-> Parser (Maybe AwsVpcConfiguration)
-> Parser NetworkConfiguration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AwsVpcConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"awsvpcConfiguration")
      )

instance Prelude.Hashable NetworkConfiguration

instance Prelude.NFData NetworkConfiguration

instance Core.ToJSON NetworkConfiguration where
  toJSON :: NetworkConfiguration -> Value
toJSON NetworkConfiguration' {Maybe AwsVpcConfiguration
awsvpcConfiguration :: Maybe AwsVpcConfiguration
$sel:awsvpcConfiguration:NetworkConfiguration' :: NetworkConfiguration -> Maybe AwsVpcConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"awsvpcConfiguration" Text -> AwsVpcConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AwsVpcConfiguration -> Pair)
-> Maybe AwsVpcConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AwsVpcConfiguration
awsvpcConfiguration
          ]
      )