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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(VpcConfig -> VpcConfig -> Bool)
-> (VpcConfig -> VpcConfig -> Bool) -> Eq VpcConfig
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]
(Int -> ReadS VpcConfig)
-> ReadS [VpcConfig]
-> ReadPrec VpcConfig
-> ReadPrec [VpcConfig]
-> Read 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
(Int -> VpcConfig -> ShowS)
-> (VpcConfig -> String)
-> ([VpcConfig] -> ShowS)
-> Show VpcConfig
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. VpcConfig -> Rep VpcConfig x)
-> (forall x. Rep VpcConfig x -> VpcConfig) -> Generic VpcConfig
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' :: NonEmpty Text -> NonEmpty Text -> VpcConfig
VpcConfig'
    { $sel:securityGroupIds:VpcConfig' :: NonEmpty Text
securityGroupIds =
        Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pSecurityGroupIds_,
      $sel:subnets:VpcConfig' :: NonEmpty Text
subnets = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
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 :: (NonEmpty Text -> f (NonEmpty Text)) -> VpcConfig -> f VpcConfig
vpcConfig_securityGroupIds = (VpcConfig -> NonEmpty Text)
-> (VpcConfig -> NonEmpty Text -> VpcConfig)
-> Lens VpcConfig VpcConfig (NonEmpty Text) (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text)) -> VpcConfig -> f VpcConfig)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> VpcConfig
-> f VpcConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
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 :: (NonEmpty Text -> f (NonEmpty Text)) -> VpcConfig -> f VpcConfig
vpcConfig_subnets = (VpcConfig -> NonEmpty Text)
-> (VpcConfig -> NonEmpty Text -> VpcConfig)
-> Lens VpcConfig VpcConfig (NonEmpty Text) (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text)) -> VpcConfig -> f VpcConfig)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> VpcConfig
-> f VpcConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON VpcConfig where
  parseJSON :: Value -> Parser VpcConfig
parseJSON =
    String -> (Object -> Parser VpcConfig) -> Value -> Parser VpcConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"VpcConfig"
      ( \Object
x ->
          NonEmpty Text -> NonEmpty Text -> VpcConfig
VpcConfig'
            (NonEmpty Text -> NonEmpty Text -> VpcConfig)
-> Parser (NonEmpty Text) -> Parser (NonEmpty Text -> VpcConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SecurityGroupIds")
            Parser (NonEmpty Text -> VpcConfig)
-> Parser (NonEmpty Text) -> Parser VpcConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Subnets")
      )

instance Prelude.Hashable VpcConfig

instance Prelude.NFData VpcConfig

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"SecurityGroupIds" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
securityGroupIds),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Subnets" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
subnets)
          ]
      )