{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.IoTThingsGraph.DeploySystemInstance
-- 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)
--
-- __Greengrass and Cloud Deployments__
--
-- Deploys the system instance to the target specified in
-- @CreateSystemInstance@.
--
-- __Greengrass Deployments__
--
-- If the system or any workflows and entities have been updated before
-- this action is called, then the deployment will create a new Amazon
-- Simple Storage Service resource file and then deploy it.
--
-- Since this action creates a Greengrass deployment on the caller\'s
-- behalf, the calling identity must have write permissions to the
-- specified Greengrass group. Otherwise, the call will fail with an
-- authorization error.
--
-- For information about the artifacts that get added to your Greengrass
-- core device when you use this API, see
-- <https://docs.aws.amazon.com/thingsgraph/latest/ug/iot-tg-greengrass.html AWS IoT Things Graph and AWS IoT Greengrass>.
module Amazonka.IoTThingsGraph.DeploySystemInstance
  ( -- * Creating a Request
    DeploySystemInstance (..),
    newDeploySystemInstance,

    -- * Request Lenses
    deploySystemInstance_id,

    -- * Destructuring the Response
    DeploySystemInstanceResponse (..),
    newDeploySystemInstanceResponse,

    -- * Response Lenses
    deploySystemInstanceResponse_greengrassDeploymentId,
    deploySystemInstanceResponse_httpStatus,
    deploySystemInstanceResponse_summary,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoTThingsGraph.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDeploySystemInstance' smart constructor.
data DeploySystemInstance = DeploySystemInstance'
  { -- | The ID of the system instance. This value is returned by the
    -- @CreateSystemInstance@ action.
    --
    -- The ID should be in the following format.
    --
    -- @urn:tdm:REGION\/ACCOUNT ID\/default:deployment:DEPLOYMENTNAME@
    DeploySystemInstance -> Maybe Text
id :: Prelude.Maybe Prelude.Text
  }
  deriving (DeploySystemInstance -> DeploySystemInstance -> Bool
(DeploySystemInstance -> DeploySystemInstance -> Bool)
-> (DeploySystemInstance -> DeploySystemInstance -> Bool)
-> Eq DeploySystemInstance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploySystemInstance -> DeploySystemInstance -> Bool
$c/= :: DeploySystemInstance -> DeploySystemInstance -> Bool
== :: DeploySystemInstance -> DeploySystemInstance -> Bool
$c== :: DeploySystemInstance -> DeploySystemInstance -> Bool
Prelude.Eq, ReadPrec [DeploySystemInstance]
ReadPrec DeploySystemInstance
Int -> ReadS DeploySystemInstance
ReadS [DeploySystemInstance]
(Int -> ReadS DeploySystemInstance)
-> ReadS [DeploySystemInstance]
-> ReadPrec DeploySystemInstance
-> ReadPrec [DeploySystemInstance]
-> Read DeploySystemInstance
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploySystemInstance]
$creadListPrec :: ReadPrec [DeploySystemInstance]
readPrec :: ReadPrec DeploySystemInstance
$creadPrec :: ReadPrec DeploySystemInstance
readList :: ReadS [DeploySystemInstance]
$creadList :: ReadS [DeploySystemInstance]
readsPrec :: Int -> ReadS DeploySystemInstance
$creadsPrec :: Int -> ReadS DeploySystemInstance
Prelude.Read, Int -> DeploySystemInstance -> ShowS
[DeploySystemInstance] -> ShowS
DeploySystemInstance -> String
(Int -> DeploySystemInstance -> ShowS)
-> (DeploySystemInstance -> String)
-> ([DeploySystemInstance] -> ShowS)
-> Show DeploySystemInstance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploySystemInstance] -> ShowS
$cshowList :: [DeploySystemInstance] -> ShowS
show :: DeploySystemInstance -> String
$cshow :: DeploySystemInstance -> String
showsPrec :: Int -> DeploySystemInstance -> ShowS
$cshowsPrec :: Int -> DeploySystemInstance -> ShowS
Prelude.Show, (forall x. DeploySystemInstance -> Rep DeploySystemInstance x)
-> (forall x. Rep DeploySystemInstance x -> DeploySystemInstance)
-> Generic DeploySystemInstance
forall x. Rep DeploySystemInstance x -> DeploySystemInstance
forall x. DeploySystemInstance -> Rep DeploySystemInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeploySystemInstance x -> DeploySystemInstance
$cfrom :: forall x. DeploySystemInstance -> Rep DeploySystemInstance x
Prelude.Generic)

-- |
-- Create a value of 'DeploySystemInstance' 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:
--
-- 'id', 'deploySystemInstance_id' - The ID of the system instance. This value is returned by the
-- @CreateSystemInstance@ action.
--
-- The ID should be in the following format.
--
-- @urn:tdm:REGION\/ACCOUNT ID\/default:deployment:DEPLOYMENTNAME@
newDeploySystemInstance ::
  DeploySystemInstance
newDeploySystemInstance :: DeploySystemInstance
newDeploySystemInstance =
  DeploySystemInstance' :: Maybe Text -> DeploySystemInstance
DeploySystemInstance' {$sel:id:DeploySystemInstance' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The ID of the system instance. This value is returned by the
-- @CreateSystemInstance@ action.
--
-- The ID should be in the following format.
--
-- @urn:tdm:REGION\/ACCOUNT ID\/default:deployment:DEPLOYMENTNAME@
deploySystemInstance_id :: Lens.Lens' DeploySystemInstance (Prelude.Maybe Prelude.Text)
deploySystemInstance_id :: (Maybe Text -> f (Maybe Text))
-> DeploySystemInstance -> f DeploySystemInstance
deploySystemInstance_id = (DeploySystemInstance -> Maybe Text)
-> (DeploySystemInstance -> Maybe Text -> DeploySystemInstance)
-> Lens
     DeploySystemInstance DeploySystemInstance (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploySystemInstance' {Maybe Text
id :: Maybe Text
$sel:id:DeploySystemInstance' :: DeploySystemInstance -> Maybe Text
id} -> Maybe Text
id) (\s :: DeploySystemInstance
s@DeploySystemInstance' {} Maybe Text
a -> DeploySystemInstance
s {$sel:id:DeploySystemInstance' :: Maybe Text
id = Maybe Text
a} :: DeploySystemInstance)

instance Core.AWSRequest DeploySystemInstance where
  type
    AWSResponse DeploySystemInstance =
      DeploySystemInstanceResponse
  request :: DeploySystemInstance -> Request DeploySystemInstance
request = Service -> DeploySystemInstance -> Request DeploySystemInstance
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeploySystemInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeploySystemInstance)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeploySystemInstance))
-> Logger
-> Service
-> Proxy DeploySystemInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeploySystemInstance)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Int -> SystemInstanceSummary -> DeploySystemInstanceResponse
DeploySystemInstanceResponse'
            (Maybe Text
 -> Int -> SystemInstanceSummary -> DeploySystemInstanceResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Int -> SystemInstanceSummary -> DeploySystemInstanceResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"greengrassDeploymentId")
            Either
  String
  (Int -> SystemInstanceSummary -> DeploySystemInstanceResponse)
-> Either String Int
-> Either
     String (SystemInstanceSummary -> DeploySystemInstanceResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either
  String (SystemInstanceSummary -> DeploySystemInstanceResponse)
-> Either String SystemInstanceSummary
-> Either String DeploySystemInstanceResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String SystemInstanceSummary
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"summary")
      )

instance Prelude.Hashable DeploySystemInstance

instance Prelude.NFData DeploySystemInstance

instance Core.ToHeaders DeploySystemInstance where
  toHeaders :: DeploySystemInstance -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeploySystemInstance -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"IotThingsGraphFrontEndService.DeploySystemInstance" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DeploySystemInstance where
  toJSON :: DeploySystemInstance -> Value
toJSON DeploySystemInstance' {Maybe Text
id :: Maybe Text
$sel:id:DeploySystemInstance' :: DeploySystemInstance -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ([Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes [(Text
"id" 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
id])

instance Core.ToPath DeploySystemInstance where
  toPath :: DeploySystemInstance -> ByteString
toPath = ByteString -> DeploySystemInstance -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DeploySystemInstance where
  toQuery :: DeploySystemInstance -> QueryString
toQuery = QueryString -> DeploySystemInstance -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDeploySystemInstanceResponse' smart constructor.
data DeploySystemInstanceResponse = DeploySystemInstanceResponse'
  { -- | The ID of the Greengrass deployment used to deploy the system instance.
    DeploySystemInstanceResponse -> Maybe Text
greengrassDeploymentId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DeploySystemInstanceResponse -> Int
httpStatus :: Prelude.Int,
    -- | An object that contains summary information about a system instance that
    -- was deployed.
    DeploySystemInstanceResponse -> SystemInstanceSummary
summary :: SystemInstanceSummary
  }
  deriving (DeploySystemInstanceResponse
-> DeploySystemInstanceResponse -> Bool
(DeploySystemInstanceResponse
 -> DeploySystemInstanceResponse -> Bool)
-> (DeploySystemInstanceResponse
    -> DeploySystemInstanceResponse -> Bool)
-> Eq DeploySystemInstanceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploySystemInstanceResponse
-> DeploySystemInstanceResponse -> Bool
$c/= :: DeploySystemInstanceResponse
-> DeploySystemInstanceResponse -> Bool
== :: DeploySystemInstanceResponse
-> DeploySystemInstanceResponse -> Bool
$c== :: DeploySystemInstanceResponse
-> DeploySystemInstanceResponse -> Bool
Prelude.Eq, ReadPrec [DeploySystemInstanceResponse]
ReadPrec DeploySystemInstanceResponse
Int -> ReadS DeploySystemInstanceResponse
ReadS [DeploySystemInstanceResponse]
(Int -> ReadS DeploySystemInstanceResponse)
-> ReadS [DeploySystemInstanceResponse]
-> ReadPrec DeploySystemInstanceResponse
-> ReadPrec [DeploySystemInstanceResponse]
-> Read DeploySystemInstanceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploySystemInstanceResponse]
$creadListPrec :: ReadPrec [DeploySystemInstanceResponse]
readPrec :: ReadPrec DeploySystemInstanceResponse
$creadPrec :: ReadPrec DeploySystemInstanceResponse
readList :: ReadS [DeploySystemInstanceResponse]
$creadList :: ReadS [DeploySystemInstanceResponse]
readsPrec :: Int -> ReadS DeploySystemInstanceResponse
$creadsPrec :: Int -> ReadS DeploySystemInstanceResponse
Prelude.Read, Int -> DeploySystemInstanceResponse -> ShowS
[DeploySystemInstanceResponse] -> ShowS
DeploySystemInstanceResponse -> String
(Int -> DeploySystemInstanceResponse -> ShowS)
-> (DeploySystemInstanceResponse -> String)
-> ([DeploySystemInstanceResponse] -> ShowS)
-> Show DeploySystemInstanceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploySystemInstanceResponse] -> ShowS
$cshowList :: [DeploySystemInstanceResponse] -> ShowS
show :: DeploySystemInstanceResponse -> String
$cshow :: DeploySystemInstanceResponse -> String
showsPrec :: Int -> DeploySystemInstanceResponse -> ShowS
$cshowsPrec :: Int -> DeploySystemInstanceResponse -> ShowS
Prelude.Show, (forall x.
 DeploySystemInstanceResponse -> Rep DeploySystemInstanceResponse x)
-> (forall x.
    Rep DeploySystemInstanceResponse x -> DeploySystemInstanceResponse)
-> Generic DeploySystemInstanceResponse
forall x.
Rep DeploySystemInstanceResponse x -> DeploySystemInstanceResponse
forall x.
DeploySystemInstanceResponse -> Rep DeploySystemInstanceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeploySystemInstanceResponse x -> DeploySystemInstanceResponse
$cfrom :: forall x.
DeploySystemInstanceResponse -> Rep DeploySystemInstanceResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeploySystemInstanceResponse' 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:
--
-- 'greengrassDeploymentId', 'deploySystemInstanceResponse_greengrassDeploymentId' - The ID of the Greengrass deployment used to deploy the system instance.
--
-- 'httpStatus', 'deploySystemInstanceResponse_httpStatus' - The response's http status code.
--
-- 'summary', 'deploySystemInstanceResponse_summary' - An object that contains summary information about a system instance that
-- was deployed.
newDeploySystemInstanceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'summary'
  SystemInstanceSummary ->
  DeploySystemInstanceResponse
newDeploySystemInstanceResponse :: Int -> SystemInstanceSummary -> DeploySystemInstanceResponse
newDeploySystemInstanceResponse
  Int
pHttpStatus_
  SystemInstanceSummary
pSummary_ =
    DeploySystemInstanceResponse' :: Maybe Text
-> Int -> SystemInstanceSummary -> DeploySystemInstanceResponse
DeploySystemInstanceResponse'
      { $sel:greengrassDeploymentId:DeploySystemInstanceResponse' :: Maybe Text
greengrassDeploymentId =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:httpStatus:DeploySystemInstanceResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:summary:DeploySystemInstanceResponse' :: SystemInstanceSummary
summary = SystemInstanceSummary
pSummary_
      }

-- | The ID of the Greengrass deployment used to deploy the system instance.
deploySystemInstanceResponse_greengrassDeploymentId :: Lens.Lens' DeploySystemInstanceResponse (Prelude.Maybe Prelude.Text)
deploySystemInstanceResponse_greengrassDeploymentId :: (Maybe Text -> f (Maybe Text))
-> DeploySystemInstanceResponse -> f DeploySystemInstanceResponse
deploySystemInstanceResponse_greengrassDeploymentId = (DeploySystemInstanceResponse -> Maybe Text)
-> (DeploySystemInstanceResponse
    -> Maybe Text -> DeploySystemInstanceResponse)
-> Lens
     DeploySystemInstanceResponse
     DeploySystemInstanceResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploySystemInstanceResponse' {Maybe Text
greengrassDeploymentId :: Maybe Text
$sel:greengrassDeploymentId:DeploySystemInstanceResponse' :: DeploySystemInstanceResponse -> Maybe Text
greengrassDeploymentId} -> Maybe Text
greengrassDeploymentId) (\s :: DeploySystemInstanceResponse
s@DeploySystemInstanceResponse' {} Maybe Text
a -> DeploySystemInstanceResponse
s {$sel:greengrassDeploymentId:DeploySystemInstanceResponse' :: Maybe Text
greengrassDeploymentId = Maybe Text
a} :: DeploySystemInstanceResponse)

-- | The response's http status code.
deploySystemInstanceResponse_httpStatus :: Lens.Lens' DeploySystemInstanceResponse Prelude.Int
deploySystemInstanceResponse_httpStatus :: (Int -> f Int)
-> DeploySystemInstanceResponse -> f DeploySystemInstanceResponse
deploySystemInstanceResponse_httpStatus = (DeploySystemInstanceResponse -> Int)
-> (DeploySystemInstanceResponse
    -> Int -> DeploySystemInstanceResponse)
-> Lens
     DeploySystemInstanceResponse DeploySystemInstanceResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploySystemInstanceResponse' {Int
httpStatus :: Int
$sel:httpStatus:DeploySystemInstanceResponse' :: DeploySystemInstanceResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DeploySystemInstanceResponse
s@DeploySystemInstanceResponse' {} Int
a -> DeploySystemInstanceResponse
s {$sel:httpStatus:DeploySystemInstanceResponse' :: Int
httpStatus = Int
a} :: DeploySystemInstanceResponse)

-- | An object that contains summary information about a system instance that
-- was deployed.
deploySystemInstanceResponse_summary :: Lens.Lens' DeploySystemInstanceResponse SystemInstanceSummary
deploySystemInstanceResponse_summary :: (SystemInstanceSummary -> f SystemInstanceSummary)
-> DeploySystemInstanceResponse -> f DeploySystemInstanceResponse
deploySystemInstanceResponse_summary = (DeploySystemInstanceResponse -> SystemInstanceSummary)
-> (DeploySystemInstanceResponse
    -> SystemInstanceSummary -> DeploySystemInstanceResponse)
-> Lens
     DeploySystemInstanceResponse
     DeploySystemInstanceResponse
     SystemInstanceSummary
     SystemInstanceSummary
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploySystemInstanceResponse' {SystemInstanceSummary
summary :: SystemInstanceSummary
$sel:summary:DeploySystemInstanceResponse' :: DeploySystemInstanceResponse -> SystemInstanceSummary
summary} -> SystemInstanceSummary
summary) (\s :: DeploySystemInstanceResponse
s@DeploySystemInstanceResponse' {} SystemInstanceSummary
a -> DeploySystemInstanceResponse
s {$sel:summary:DeploySystemInstanceResponse' :: SystemInstanceSummary
summary = SystemInstanceSummary
a} :: DeploySystemInstanceResponse)

instance Prelude.NFData DeploySystemInstanceResponse