{-# 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.SageMaker.Types.VpcConfig
-- 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.SageMaker.Types.VpcConfig 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

-- | Specifies a VPC that your training jobs and hosted models have access
-- to. Control access to and from your training and model containers by
-- configuring the VPC. For more information, see
-- <https://docs.aws.amazon.com/sagemaker/latest/dg/host-vpc.html Protect Endpoints by Using an Amazon Virtual Private Cloud>
-- and
-- <https://docs.aws.amazon.com/sagemaker/latest/dg/train-vpc.html Protect Training Jobs by Using an Amazon Virtual Private Cloud>.
--
-- /See:/ 'newVpcConfig' smart constructor.
data VpcConfig = VpcConfig'
  { -- | The VPC security group IDs, in the form sg-xxxxxxxx. Specify the
    -- security groups for the VPC that is specified in the @Subnets@ field.
    VpcConfig -> NonEmpty Text
securityGroupIds :: Prelude.NonEmpty Prelude.Text,
    -- | The ID of the subnets in the VPC to which you want to connect your
    -- training job or model. For information about the availability of
    -- specific instance types, see
    -- <https://docs.aws.amazon.com/sagemaker/latest/dg/instance-types-az.html Supported Instance Types and Availability Zones>.
    VpcConfig -> NonEmpty Text
subnets :: Prelude.NonEmpty Prelude.Text
  }
  deriving (VpcConfig -> VpcConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VpcConfig -> VpcConfig -> Bool
$c/= :: VpcConfig -> VpcConfig -> Bool
== :: VpcConfig -> VpcConfig -> Bool
$c== :: VpcConfig -> VpcConfig -> Bool
Prelude.Eq, ReadPrec [VpcConfig]
ReadPrec VpcConfig
Int -> ReadS VpcConfig
ReadS [VpcConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VpcConfig]
$creadListPrec :: ReadPrec [VpcConfig]
readPrec :: ReadPrec VpcConfig
$creadPrec :: ReadPrec VpcConfig
readList :: ReadS [VpcConfig]
$creadList :: ReadS [VpcConfig]
readsPrec :: Int -> ReadS VpcConfig
$creadsPrec :: Int -> ReadS VpcConfig
Prelude.Read, Int -> VpcConfig -> ShowS
[VpcConfig] -> ShowS
VpcConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VpcConfig] -> ShowS
$cshowList :: [VpcConfig] -> ShowS
show :: VpcConfig -> String
$cshow :: VpcConfig -> String
showsPrec :: Int -> VpcConfig -> ShowS
$cshowsPrec :: Int -> VpcConfig -> ShowS
Prelude.Show, forall x. Rep VpcConfig x -> VpcConfig
forall x. VpcConfig -> Rep VpcConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VpcConfig x -> VpcConfig
$cfrom :: forall x. VpcConfig -> Rep VpcConfig x
Prelude.Generic)

-- |
-- Create a value of 'VpcConfig' 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:
--
-- 'securityGroupIds', 'vpcConfig_securityGroupIds' - The VPC security group IDs, in the form sg-xxxxxxxx. Specify the
-- security groups for the VPC that is specified in the @Subnets@ field.
--
-- 'subnets', 'vpcConfig_subnets' - The ID of the subnets in the VPC to which you want to connect your
-- training job or model. For information about the availability of
-- specific instance types, see
-- <https://docs.aws.amazon.com/sagemaker/latest/dg/instance-types-az.html Supported Instance Types and Availability Zones>.
newVpcConfig ::
  -- | 'securityGroupIds'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'subnets'
  Prelude.NonEmpty Prelude.Text ->
  VpcConfig
newVpcConfig :: NonEmpty Text -> NonEmpty Text -> VpcConfig
newVpcConfig NonEmpty Text
pSecurityGroupIds_ NonEmpty Text
pSubnets_ =
  VpcConfig'
    { $sel:securityGroupIds:VpcConfig' :: NonEmpty Text
securityGroupIds =
        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
pSecurityGroupIds_,
      $sel:subnets:VpcConfig' :: NonEmpty Text
subnets = 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
pSubnets_
    }

-- | The VPC security group IDs, in the form sg-xxxxxxxx. Specify the
-- security groups for the VPC that is specified in the @Subnets@ field.
vpcConfig_securityGroupIds :: Lens.Lens' VpcConfig (Prelude.NonEmpty Prelude.Text)
vpcConfig_securityGroupIds :: Lens' VpcConfig (NonEmpty Text)
vpcConfig_securityGroupIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VpcConfig' {NonEmpty Text
securityGroupIds :: NonEmpty Text
$sel:securityGroupIds:VpcConfig' :: VpcConfig -> NonEmpty Text
securityGroupIds} -> NonEmpty Text
securityGroupIds) (\s :: VpcConfig
s@VpcConfig' {} NonEmpty Text
a -> VpcConfig
s {$sel:securityGroupIds:VpcConfig' :: NonEmpty Text
securityGroupIds = NonEmpty Text
a} :: VpcConfig) 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

-- | The ID of the subnets in the VPC to which you want to connect your
-- training job or model. For information about the availability of
-- specific instance types, see
-- <https://docs.aws.amazon.com/sagemaker/latest/dg/instance-types-az.html Supported Instance Types and Availability Zones>.
vpcConfig_subnets :: Lens.Lens' VpcConfig (Prelude.NonEmpty Prelude.Text)
vpcConfig_subnets :: Lens' VpcConfig (NonEmpty Text)
vpcConfig_subnets = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VpcConfig' {NonEmpty Text
subnets :: NonEmpty Text
$sel:subnets:VpcConfig' :: VpcConfig -> NonEmpty Text
subnets} -> NonEmpty Text
subnets) (\s :: VpcConfig
s@VpcConfig' {} NonEmpty Text
a -> VpcConfig
s {$sel:subnets:VpcConfig' :: NonEmpty Text
subnets = NonEmpty Text
a} :: VpcConfig) 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 VpcConfig where
  parseJSON :: Value -> Parser VpcConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"VpcConfig"
      ( \Object
x ->
          NonEmpty Text -> NonEmpty Text -> VpcConfig
VpcConfig'
            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
"SecurityGroupIds")
            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
"Subnets")
      )

instance Prelude.Hashable VpcConfig where
  hashWithSalt :: Int -> VpcConfig -> Int
hashWithSalt Int
_salt VpcConfig' {NonEmpty Text
subnets :: NonEmpty Text
securityGroupIds :: NonEmpty Text
$sel:subnets:VpcConfig' :: VpcConfig -> NonEmpty Text
$sel:securityGroupIds:VpcConfig' :: VpcConfig -> NonEmpty Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
securityGroupIds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
subnets

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

instance Data.ToJSON VpcConfig where
  toJSON :: VpcConfig -> Value
toJSON VpcConfig' {NonEmpty Text
subnets :: NonEmpty Text
securityGroupIds :: NonEmpty Text
$sel:subnets:VpcConfig' :: VpcConfig -> NonEmpty Text
$sel:securityGroupIds:VpcConfig' :: VpcConfig -> NonEmpty Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"SecurityGroupIds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
securityGroupIds),
            forall a. a -> Maybe a
Prelude.Just (Key
"Subnets" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
subnets)
          ]
      )