{-# 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.IAM.AddRoleToInstanceProfile
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds the specified IAM role to the specified instance profile. An
-- instance profile can contain only one role, and this quota cannot be
-- increased. You can remove the existing role and then add a different
-- role to an instance profile. You must then wait for the change to appear
-- across all of Amazon Web Services because of
-- <https://en.wikipedia.org/wiki/Eventual_consistency eventual consistency>.
-- To force the change, you must
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DisassociateIamInstanceProfile.html disassociate the instance profile>
-- and then
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssociateIamInstanceProfile.html associate the instance profile>,
-- or you can stop your instance and then restart it.
--
-- The caller of this operation must be granted the @PassRole@ permission
-- on the IAM role by a permissions policy.
--
-- For more information about roles, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/WorkingWithRoles.html Working with roles>.
-- For more information about instance profiles, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/AboutInstanceProfiles.html About instance profiles>.
module Amazonka.IAM.AddRoleToInstanceProfile
  ( -- * Creating a Request
    AddRoleToInstanceProfile (..),
    newAddRoleToInstanceProfile,

    -- * Request Lenses
    addRoleToInstanceProfile_instanceProfileName,
    addRoleToInstanceProfile_roleName,

    -- * Destructuring the Response
    AddRoleToInstanceProfileResponse (..),
    newAddRoleToInstanceProfileResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IAM.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAddRoleToInstanceProfile' smart constructor.
data AddRoleToInstanceProfile = AddRoleToInstanceProfile'
  { -- | The name of the instance profile to update.
    --
    -- This parameter allows (through its
    -- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
    -- consisting of upper and lowercase alphanumeric characters with no
    -- spaces. You can also include any of the following characters: _+=,.\@-
    AddRoleToInstanceProfile -> Text
instanceProfileName :: Prelude.Text,
    -- | The name of the role to add.
    --
    -- This parameter allows (through its
    -- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
    -- consisting of upper and lowercase alphanumeric characters with no
    -- spaces. You can also include any of the following characters: _+=,.\@-
    AddRoleToInstanceProfile -> Text
roleName :: Prelude.Text
  }
  deriving (AddRoleToInstanceProfile -> AddRoleToInstanceProfile -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddRoleToInstanceProfile -> AddRoleToInstanceProfile -> Bool
$c/= :: AddRoleToInstanceProfile -> AddRoleToInstanceProfile -> Bool
== :: AddRoleToInstanceProfile -> AddRoleToInstanceProfile -> Bool
$c== :: AddRoleToInstanceProfile -> AddRoleToInstanceProfile -> Bool
Prelude.Eq, ReadPrec [AddRoleToInstanceProfile]
ReadPrec AddRoleToInstanceProfile
Int -> ReadS AddRoleToInstanceProfile
ReadS [AddRoleToInstanceProfile]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddRoleToInstanceProfile]
$creadListPrec :: ReadPrec [AddRoleToInstanceProfile]
readPrec :: ReadPrec AddRoleToInstanceProfile
$creadPrec :: ReadPrec AddRoleToInstanceProfile
readList :: ReadS [AddRoleToInstanceProfile]
$creadList :: ReadS [AddRoleToInstanceProfile]
readsPrec :: Int -> ReadS AddRoleToInstanceProfile
$creadsPrec :: Int -> ReadS AddRoleToInstanceProfile
Prelude.Read, Int -> AddRoleToInstanceProfile -> ShowS
[AddRoleToInstanceProfile] -> ShowS
AddRoleToInstanceProfile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddRoleToInstanceProfile] -> ShowS
$cshowList :: [AddRoleToInstanceProfile] -> ShowS
show :: AddRoleToInstanceProfile -> String
$cshow :: AddRoleToInstanceProfile -> String
showsPrec :: Int -> AddRoleToInstanceProfile -> ShowS
$cshowsPrec :: Int -> AddRoleToInstanceProfile -> ShowS
Prelude.Show, forall x.
Rep AddRoleToInstanceProfile x -> AddRoleToInstanceProfile
forall x.
AddRoleToInstanceProfile -> Rep AddRoleToInstanceProfile x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AddRoleToInstanceProfile x -> AddRoleToInstanceProfile
$cfrom :: forall x.
AddRoleToInstanceProfile -> Rep AddRoleToInstanceProfile x
Prelude.Generic)

-- |
-- Create a value of 'AddRoleToInstanceProfile' 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:
--
-- 'instanceProfileName', 'addRoleToInstanceProfile_instanceProfileName' - The name of the instance profile to update.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
--
-- 'roleName', 'addRoleToInstanceProfile_roleName' - The name of the role to add.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
newAddRoleToInstanceProfile ::
  -- | 'instanceProfileName'
  Prelude.Text ->
  -- | 'roleName'
  Prelude.Text ->
  AddRoleToInstanceProfile
newAddRoleToInstanceProfile :: Text -> Text -> AddRoleToInstanceProfile
newAddRoleToInstanceProfile
  Text
pInstanceProfileName_
  Text
pRoleName_ =
    AddRoleToInstanceProfile'
      { $sel:instanceProfileName:AddRoleToInstanceProfile' :: Text
instanceProfileName =
          Text
pInstanceProfileName_,
        $sel:roleName:AddRoleToInstanceProfile' :: Text
roleName = Text
pRoleName_
      }

-- | The name of the instance profile to update.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
addRoleToInstanceProfile_instanceProfileName :: Lens.Lens' AddRoleToInstanceProfile Prelude.Text
addRoleToInstanceProfile_instanceProfileName :: Lens' AddRoleToInstanceProfile Text
addRoleToInstanceProfile_instanceProfileName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddRoleToInstanceProfile' {Text
instanceProfileName :: Text
$sel:instanceProfileName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
instanceProfileName} -> Text
instanceProfileName) (\s :: AddRoleToInstanceProfile
s@AddRoleToInstanceProfile' {} Text
a -> AddRoleToInstanceProfile
s {$sel:instanceProfileName:AddRoleToInstanceProfile' :: Text
instanceProfileName = Text
a} :: AddRoleToInstanceProfile)

-- | The name of the role to add.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
addRoleToInstanceProfile_roleName :: Lens.Lens' AddRoleToInstanceProfile Prelude.Text
addRoleToInstanceProfile_roleName :: Lens' AddRoleToInstanceProfile Text
addRoleToInstanceProfile_roleName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddRoleToInstanceProfile' {Text
roleName :: Text
$sel:roleName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
roleName} -> Text
roleName) (\s :: AddRoleToInstanceProfile
s@AddRoleToInstanceProfile' {} Text
a -> AddRoleToInstanceProfile
s {$sel:roleName:AddRoleToInstanceProfile' :: Text
roleName = Text
a} :: AddRoleToInstanceProfile)

instance Core.AWSRequest AddRoleToInstanceProfile where
  type
    AWSResponse AddRoleToInstanceProfile =
      AddRoleToInstanceProfileResponse
  request :: (Service -> Service)
-> AddRoleToInstanceProfile -> Request AddRoleToInstanceProfile
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AddRoleToInstanceProfile
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddRoleToInstanceProfile)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AddRoleToInstanceProfileResponse
AddRoleToInstanceProfileResponse'

instance Prelude.Hashable AddRoleToInstanceProfile where
  hashWithSalt :: Int -> AddRoleToInstanceProfile -> Int
hashWithSalt Int
_salt AddRoleToInstanceProfile' {Text
roleName :: Text
instanceProfileName :: Text
$sel:roleName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
$sel:instanceProfileName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
instanceProfileName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleName

instance Prelude.NFData AddRoleToInstanceProfile where
  rnf :: AddRoleToInstanceProfile -> ()
rnf AddRoleToInstanceProfile' {Text
roleName :: Text
instanceProfileName :: Text
$sel:roleName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
$sel:instanceProfileName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
instanceProfileName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
roleName

instance Data.ToHeaders AddRoleToInstanceProfile where
  toHeaders :: AddRoleToInstanceProfile -> [Header]
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToQuery AddRoleToInstanceProfile where
  toQuery :: AddRoleToInstanceProfile -> QueryString
toQuery AddRoleToInstanceProfile' {Text
roleName :: Text
instanceProfileName :: Text
$sel:roleName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
$sel:instanceProfileName:AddRoleToInstanceProfile' :: AddRoleToInstanceProfile -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"AddRoleToInstanceProfile" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"InstanceProfileName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
instanceProfileName,
        ByteString
"RoleName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
roleName
      ]

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

-- |
-- Create a value of 'AddRoleToInstanceProfileResponse' 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.
newAddRoleToInstanceProfileResponse ::
  AddRoleToInstanceProfileResponse
newAddRoleToInstanceProfileResponse :: AddRoleToInstanceProfileResponse
newAddRoleToInstanceProfileResponse =
  AddRoleToInstanceProfileResponse
AddRoleToInstanceProfileResponse'

instance
  Prelude.NFData
    AddRoleToInstanceProfileResponse
  where
  rnf :: AddRoleToInstanceProfileResponse -> ()
rnf AddRoleToInstanceProfileResponse
_ = ()