{-# 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.SSM.UpdateManagedInstanceRole
-- 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)
--
-- Changes the Identity and Access Management (IAM) role that is assigned
-- to the on-premises instance or virtual machines (VM). IAM roles are
-- first assigned to these hybrid instances during the activation process.
-- For more information, see CreateActivation.
module Amazonka.SSM.UpdateManagedInstanceRole
  ( -- * Creating a Request
    UpdateManagedInstanceRole (..),
    newUpdateManagedInstanceRole,

    -- * Request Lenses
    updateManagedInstanceRole_instanceId,
    updateManagedInstanceRole_iamRole,

    -- * Destructuring the Response
    UpdateManagedInstanceRoleResponse (..),
    newUpdateManagedInstanceRoleResponse,

    -- * Response Lenses
    updateManagedInstanceRoleResponse_httpStatus,
  )
where

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

-- | /See:/ 'newUpdateManagedInstanceRole' smart constructor.
data UpdateManagedInstanceRole = UpdateManagedInstanceRole'
  { -- | The ID of the managed instance where you want to update the role.
    UpdateManagedInstanceRole -> Text
instanceId :: Prelude.Text,
    -- | The IAM role you want to assign or change.
    UpdateManagedInstanceRole -> Text
iamRole :: Prelude.Text
  }
  deriving (UpdateManagedInstanceRole -> UpdateManagedInstanceRole -> Bool
(UpdateManagedInstanceRole -> UpdateManagedInstanceRole -> Bool)
-> (UpdateManagedInstanceRole -> UpdateManagedInstanceRole -> Bool)
-> Eq UpdateManagedInstanceRole
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateManagedInstanceRole -> UpdateManagedInstanceRole -> Bool
$c/= :: UpdateManagedInstanceRole -> UpdateManagedInstanceRole -> Bool
== :: UpdateManagedInstanceRole -> UpdateManagedInstanceRole -> Bool
$c== :: UpdateManagedInstanceRole -> UpdateManagedInstanceRole -> Bool
Prelude.Eq, ReadPrec [UpdateManagedInstanceRole]
ReadPrec UpdateManagedInstanceRole
Int -> ReadS UpdateManagedInstanceRole
ReadS [UpdateManagedInstanceRole]
(Int -> ReadS UpdateManagedInstanceRole)
-> ReadS [UpdateManagedInstanceRole]
-> ReadPrec UpdateManagedInstanceRole
-> ReadPrec [UpdateManagedInstanceRole]
-> Read UpdateManagedInstanceRole
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateManagedInstanceRole]
$creadListPrec :: ReadPrec [UpdateManagedInstanceRole]
readPrec :: ReadPrec UpdateManagedInstanceRole
$creadPrec :: ReadPrec UpdateManagedInstanceRole
readList :: ReadS [UpdateManagedInstanceRole]
$creadList :: ReadS [UpdateManagedInstanceRole]
readsPrec :: Int -> ReadS UpdateManagedInstanceRole
$creadsPrec :: Int -> ReadS UpdateManagedInstanceRole
Prelude.Read, Int -> UpdateManagedInstanceRole -> ShowS
[UpdateManagedInstanceRole] -> ShowS
UpdateManagedInstanceRole -> String
(Int -> UpdateManagedInstanceRole -> ShowS)
-> (UpdateManagedInstanceRole -> String)
-> ([UpdateManagedInstanceRole] -> ShowS)
-> Show UpdateManagedInstanceRole
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateManagedInstanceRole] -> ShowS
$cshowList :: [UpdateManagedInstanceRole] -> ShowS
show :: UpdateManagedInstanceRole -> String
$cshow :: UpdateManagedInstanceRole -> String
showsPrec :: Int -> UpdateManagedInstanceRole -> ShowS
$cshowsPrec :: Int -> UpdateManagedInstanceRole -> ShowS
Prelude.Show, (forall x.
 UpdateManagedInstanceRole -> Rep UpdateManagedInstanceRole x)
-> (forall x.
    Rep UpdateManagedInstanceRole x -> UpdateManagedInstanceRole)
-> Generic UpdateManagedInstanceRole
forall x.
Rep UpdateManagedInstanceRole x -> UpdateManagedInstanceRole
forall x.
UpdateManagedInstanceRole -> Rep UpdateManagedInstanceRole x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateManagedInstanceRole x -> UpdateManagedInstanceRole
$cfrom :: forall x.
UpdateManagedInstanceRole -> Rep UpdateManagedInstanceRole x
Prelude.Generic)

-- |
-- Create a value of 'UpdateManagedInstanceRole' 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:
--
-- 'instanceId', 'updateManagedInstanceRole_instanceId' - The ID of the managed instance where you want to update the role.
--
-- 'iamRole', 'updateManagedInstanceRole_iamRole' - The IAM role you want to assign or change.
newUpdateManagedInstanceRole ::
  -- | 'instanceId'
  Prelude.Text ->
  -- | 'iamRole'
  Prelude.Text ->
  UpdateManagedInstanceRole
newUpdateManagedInstanceRole :: Text -> Text -> UpdateManagedInstanceRole
newUpdateManagedInstanceRole Text
pInstanceId_ Text
pIamRole_ =
  UpdateManagedInstanceRole' :: Text -> Text -> UpdateManagedInstanceRole
UpdateManagedInstanceRole'
    { $sel:instanceId:UpdateManagedInstanceRole' :: Text
instanceId =
        Text
pInstanceId_,
      $sel:iamRole:UpdateManagedInstanceRole' :: Text
iamRole = Text
pIamRole_
    }

-- | The ID of the managed instance where you want to update the role.
updateManagedInstanceRole_instanceId :: Lens.Lens' UpdateManagedInstanceRole Prelude.Text
updateManagedInstanceRole_instanceId :: (Text -> f Text)
-> UpdateManagedInstanceRole -> f UpdateManagedInstanceRole
updateManagedInstanceRole_instanceId = (UpdateManagedInstanceRole -> Text)
-> (UpdateManagedInstanceRole -> Text -> UpdateManagedInstanceRole)
-> Lens
     UpdateManagedInstanceRole UpdateManagedInstanceRole Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateManagedInstanceRole' {Text
instanceId :: Text
$sel:instanceId:UpdateManagedInstanceRole' :: UpdateManagedInstanceRole -> Text
instanceId} -> Text
instanceId) (\s :: UpdateManagedInstanceRole
s@UpdateManagedInstanceRole' {} Text
a -> UpdateManagedInstanceRole
s {$sel:instanceId:UpdateManagedInstanceRole' :: Text
instanceId = Text
a} :: UpdateManagedInstanceRole)

-- | The IAM role you want to assign or change.
updateManagedInstanceRole_iamRole :: Lens.Lens' UpdateManagedInstanceRole Prelude.Text
updateManagedInstanceRole_iamRole :: (Text -> f Text)
-> UpdateManagedInstanceRole -> f UpdateManagedInstanceRole
updateManagedInstanceRole_iamRole = (UpdateManagedInstanceRole -> Text)
-> (UpdateManagedInstanceRole -> Text -> UpdateManagedInstanceRole)
-> Lens
     UpdateManagedInstanceRole UpdateManagedInstanceRole Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateManagedInstanceRole' {Text
iamRole :: Text
$sel:iamRole:UpdateManagedInstanceRole' :: UpdateManagedInstanceRole -> Text
iamRole} -> Text
iamRole) (\s :: UpdateManagedInstanceRole
s@UpdateManagedInstanceRole' {} Text
a -> UpdateManagedInstanceRole
s {$sel:iamRole:UpdateManagedInstanceRole' :: Text
iamRole = Text
a} :: UpdateManagedInstanceRole)

instance Core.AWSRequest UpdateManagedInstanceRole where
  type
    AWSResponse UpdateManagedInstanceRole =
      UpdateManagedInstanceRoleResponse
  request :: UpdateManagedInstanceRole -> Request UpdateManagedInstanceRole
request = Service
-> UpdateManagedInstanceRole -> Request UpdateManagedInstanceRole
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateManagedInstanceRole
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateManagedInstanceRole)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateManagedInstanceRole))
-> Logger
-> Service
-> Proxy UpdateManagedInstanceRole
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateManagedInstanceRole)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdateManagedInstanceRoleResponse
UpdateManagedInstanceRoleResponse'
            (Int -> UpdateManagedInstanceRoleResponse)
-> Either String Int
-> Either String UpdateManagedInstanceRoleResponse
forall (f :: * -> *) a b. Functor 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))
      )

instance Prelude.Hashable UpdateManagedInstanceRole

instance Prelude.NFData UpdateManagedInstanceRole

instance Core.ToHeaders UpdateManagedInstanceRole where
  toHeaders :: UpdateManagedInstanceRole -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateManagedInstanceRole -> 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
"AmazonSSM.UpdateManagedInstanceRole" ::
                          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 UpdateManagedInstanceRole where
  toJSON :: UpdateManagedInstanceRole -> Value
toJSON UpdateManagedInstanceRole' {Text
iamRole :: Text
instanceId :: Text
$sel:iamRole:UpdateManagedInstanceRole' :: UpdateManagedInstanceRole -> Text
$sel:instanceId:UpdateManagedInstanceRole' :: UpdateManagedInstanceRole -> 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
"InstanceId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"IamRole" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
iamRole)
          ]
      )

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

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

-- | /See:/ 'newUpdateManagedInstanceRoleResponse' smart constructor.
data UpdateManagedInstanceRoleResponse = UpdateManagedInstanceRoleResponse'
  { -- | The response's http status code.
    UpdateManagedInstanceRoleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateManagedInstanceRoleResponse
-> UpdateManagedInstanceRoleResponse -> Bool
(UpdateManagedInstanceRoleResponse
 -> UpdateManagedInstanceRoleResponse -> Bool)
-> (UpdateManagedInstanceRoleResponse
    -> UpdateManagedInstanceRoleResponse -> Bool)
-> Eq UpdateManagedInstanceRoleResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateManagedInstanceRoleResponse
-> UpdateManagedInstanceRoleResponse -> Bool
$c/= :: UpdateManagedInstanceRoleResponse
-> UpdateManagedInstanceRoleResponse -> Bool
== :: UpdateManagedInstanceRoleResponse
-> UpdateManagedInstanceRoleResponse -> Bool
$c== :: UpdateManagedInstanceRoleResponse
-> UpdateManagedInstanceRoleResponse -> Bool
Prelude.Eq, ReadPrec [UpdateManagedInstanceRoleResponse]
ReadPrec UpdateManagedInstanceRoleResponse
Int -> ReadS UpdateManagedInstanceRoleResponse
ReadS [UpdateManagedInstanceRoleResponse]
(Int -> ReadS UpdateManagedInstanceRoleResponse)
-> ReadS [UpdateManagedInstanceRoleResponse]
-> ReadPrec UpdateManagedInstanceRoleResponse
-> ReadPrec [UpdateManagedInstanceRoleResponse]
-> Read UpdateManagedInstanceRoleResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateManagedInstanceRoleResponse]
$creadListPrec :: ReadPrec [UpdateManagedInstanceRoleResponse]
readPrec :: ReadPrec UpdateManagedInstanceRoleResponse
$creadPrec :: ReadPrec UpdateManagedInstanceRoleResponse
readList :: ReadS [UpdateManagedInstanceRoleResponse]
$creadList :: ReadS [UpdateManagedInstanceRoleResponse]
readsPrec :: Int -> ReadS UpdateManagedInstanceRoleResponse
$creadsPrec :: Int -> ReadS UpdateManagedInstanceRoleResponse
Prelude.Read, Int -> UpdateManagedInstanceRoleResponse -> ShowS
[UpdateManagedInstanceRoleResponse] -> ShowS
UpdateManagedInstanceRoleResponse -> String
(Int -> UpdateManagedInstanceRoleResponse -> ShowS)
-> (UpdateManagedInstanceRoleResponse -> String)
-> ([UpdateManagedInstanceRoleResponse] -> ShowS)
-> Show UpdateManagedInstanceRoleResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateManagedInstanceRoleResponse] -> ShowS
$cshowList :: [UpdateManagedInstanceRoleResponse] -> ShowS
show :: UpdateManagedInstanceRoleResponse -> String
$cshow :: UpdateManagedInstanceRoleResponse -> String
showsPrec :: Int -> UpdateManagedInstanceRoleResponse -> ShowS
$cshowsPrec :: Int -> UpdateManagedInstanceRoleResponse -> ShowS
Prelude.Show, (forall x.
 UpdateManagedInstanceRoleResponse
 -> Rep UpdateManagedInstanceRoleResponse x)
-> (forall x.
    Rep UpdateManagedInstanceRoleResponse x
    -> UpdateManagedInstanceRoleResponse)
-> Generic UpdateManagedInstanceRoleResponse
forall x.
Rep UpdateManagedInstanceRoleResponse x
-> UpdateManagedInstanceRoleResponse
forall x.
UpdateManagedInstanceRoleResponse
-> Rep UpdateManagedInstanceRoleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateManagedInstanceRoleResponse x
-> UpdateManagedInstanceRoleResponse
$cfrom :: forall x.
UpdateManagedInstanceRoleResponse
-> Rep UpdateManagedInstanceRoleResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateManagedInstanceRoleResponse' 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:
--
-- 'httpStatus', 'updateManagedInstanceRoleResponse_httpStatus' - The response's http status code.
newUpdateManagedInstanceRoleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateManagedInstanceRoleResponse
newUpdateManagedInstanceRoleResponse :: Int -> UpdateManagedInstanceRoleResponse
newUpdateManagedInstanceRoleResponse Int
pHttpStatus_ =
  UpdateManagedInstanceRoleResponse' :: Int -> UpdateManagedInstanceRoleResponse
UpdateManagedInstanceRoleResponse'
    { $sel:httpStatus:UpdateManagedInstanceRoleResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance
  Prelude.NFData
    UpdateManagedInstanceRoleResponse