{-# 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-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)
--
-- 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 Amazonka.IAM.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:/ '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
(AddRoleToInstanceProfile -> AddRoleToInstanceProfile -> Bool)
-> (AddRoleToInstanceProfile -> AddRoleToInstanceProfile -> Bool)
-> Eq AddRoleToInstanceProfile
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]
(Int -> ReadS AddRoleToInstanceProfile)
-> ReadS [AddRoleToInstanceProfile]
-> ReadPrec AddRoleToInstanceProfile
-> ReadPrec [AddRoleToInstanceProfile]
-> Read 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
(Int -> AddRoleToInstanceProfile -> ShowS)
-> (AddRoleToInstanceProfile -> String)
-> ([AddRoleToInstanceProfile] -> ShowS)
-> Show AddRoleToInstanceProfile
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.
 AddRoleToInstanceProfile -> Rep AddRoleToInstanceProfile x)
-> (forall x.
    Rep AddRoleToInstanceProfile x -> AddRoleToInstanceProfile)
-> Generic AddRoleToInstanceProfile
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' :: Text -> Text -> AddRoleToInstanceProfile
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 :: (Text -> f Text)
-> AddRoleToInstanceProfile -> f AddRoleToInstanceProfile
addRoleToInstanceProfile_instanceProfileName = (AddRoleToInstanceProfile -> Text)
-> (AddRoleToInstanceProfile -> Text -> AddRoleToInstanceProfile)
-> Lens AddRoleToInstanceProfile AddRoleToInstanceProfile Text Text
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 :: (Text -> f Text)
-> AddRoleToInstanceProfile -> f AddRoleToInstanceProfile
addRoleToInstanceProfile_roleName = (AddRoleToInstanceProfile -> Text)
-> (AddRoleToInstanceProfile -> Text -> AddRoleToInstanceProfile)
-> Lens AddRoleToInstanceProfile AddRoleToInstanceProfile Text Text
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 :: AddRoleToInstanceProfile -> Request AddRoleToInstanceProfile
request = Service
-> AddRoleToInstanceProfile -> Request AddRoleToInstanceProfile
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy AddRoleToInstanceProfile
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddRoleToInstanceProfile)))
response =
    AWSResponse AddRoleToInstanceProfile
-> Logger
-> Service
-> Proxy AddRoleToInstanceProfile
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddRoleToInstanceProfile)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AWSResponse AddRoleToInstanceProfile
AddRoleToInstanceProfileResponse
AddRoleToInstanceProfileResponse'

instance Prelude.Hashable AddRoleToInstanceProfile

instance Prelude.NFData AddRoleToInstanceProfile

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

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

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

-- | /See:/ 'newAddRoleToInstanceProfileResponse' smart constructor.
data AddRoleToInstanceProfileResponse = AddRoleToInstanceProfileResponse'
  {
  }
  deriving (AddRoleToInstanceProfileResponse
-> AddRoleToInstanceProfileResponse -> Bool
(AddRoleToInstanceProfileResponse
 -> AddRoleToInstanceProfileResponse -> Bool)
-> (AddRoleToInstanceProfileResponse
    -> AddRoleToInstanceProfileResponse -> Bool)
-> Eq AddRoleToInstanceProfileResponse
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]
(Int -> ReadS AddRoleToInstanceProfileResponse)
-> ReadS [AddRoleToInstanceProfileResponse]
-> ReadPrec AddRoleToInstanceProfileResponse
-> ReadPrec [AddRoleToInstanceProfileResponse]
-> Read 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
(Int -> AddRoleToInstanceProfileResponse -> ShowS)
-> (AddRoleToInstanceProfileResponse -> String)
-> ([AddRoleToInstanceProfileResponse] -> ShowS)
-> Show AddRoleToInstanceProfileResponse
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.
 AddRoleToInstanceProfileResponse
 -> Rep AddRoleToInstanceProfileResponse x)
-> (forall x.
    Rep AddRoleToInstanceProfileResponse x
    -> AddRoleToInstanceProfileResponse)
-> Generic AddRoleToInstanceProfileResponse
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