{-# 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.OpsWorks.AssignVolume
-- 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)
--
-- Assigns one of the stack\'s registered Amazon EBS volumes to a specified
-- instance. The volume must first be registered with the stack by calling
-- RegisterVolume. After you register the volume, you must call
-- UpdateVolume to specify a mount point before calling @AssignVolume@. For
-- more information, see
-- <https://docs.aws.amazon.com/opsworks/latest/userguide/resources.html Resource Management>.
--
-- __Required Permissions__: To use this action, an IAM user must have a
-- Manage permissions level for the stack, or an attached policy that
-- explicitly grants permissions. For more information on user permissions,
-- see
-- <https://docs.aws.amazon.com/opsworks/latest/userguide/opsworks-security-users.html Managing User Permissions>.
module Amazonka.OpsWorks.AssignVolume
  ( -- * Creating a Request
    AssignVolume (..),
    newAssignVolume,

    -- * Request Lenses
    assignVolume_instanceId,
    assignVolume_volumeId,

    -- * Destructuring the Response
    AssignVolumeResponse (..),
    newAssignVolumeResponse,
  )
where

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

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

-- |
-- Create a value of 'AssignVolume' 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', 'assignVolume_instanceId' - The instance ID.
--
-- 'volumeId', 'assignVolume_volumeId' - The volume ID.
newAssignVolume ::
  -- | 'volumeId'
  Prelude.Text ->
  AssignVolume
newAssignVolume :: Text -> AssignVolume
newAssignVolume Text
pVolumeId_ =
  AssignVolume' :: Maybe Text -> Text -> AssignVolume
AssignVolume'
    { $sel:instanceId:AssignVolume' :: Maybe Text
instanceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:volumeId:AssignVolume' :: Text
volumeId = Text
pVolumeId_
    }

-- | The instance ID.
assignVolume_instanceId :: Lens.Lens' AssignVolume (Prelude.Maybe Prelude.Text)
assignVolume_instanceId :: (Maybe Text -> f (Maybe Text)) -> AssignVolume -> f AssignVolume
assignVolume_instanceId = (AssignVolume -> Maybe Text)
-> (AssignVolume -> Maybe Text -> AssignVolume)
-> Lens AssignVolume AssignVolume (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssignVolume' {Maybe Text
instanceId :: Maybe Text
$sel:instanceId:AssignVolume' :: AssignVolume -> Maybe Text
instanceId} -> Maybe Text
instanceId) (\s :: AssignVolume
s@AssignVolume' {} Maybe Text
a -> AssignVolume
s {$sel:instanceId:AssignVolume' :: Maybe Text
instanceId = Maybe Text
a} :: AssignVolume)

-- | The volume ID.
assignVolume_volumeId :: Lens.Lens' AssignVolume Prelude.Text
assignVolume_volumeId :: (Text -> f Text) -> AssignVolume -> f AssignVolume
assignVolume_volumeId = (AssignVolume -> Text)
-> (AssignVolume -> Text -> AssignVolume)
-> Lens AssignVolume AssignVolume Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssignVolume' {Text
volumeId :: Text
$sel:volumeId:AssignVolume' :: AssignVolume -> Text
volumeId} -> Text
volumeId) (\s :: AssignVolume
s@AssignVolume' {} Text
a -> AssignVolume
s {$sel:volumeId:AssignVolume' :: Text
volumeId = Text
a} :: AssignVolume)

instance Core.AWSRequest AssignVolume where
  type AWSResponse AssignVolume = AssignVolumeResponse
  request :: AssignVolume -> Request AssignVolume
request = Service -> AssignVolume -> Request AssignVolume
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AssignVolume
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssignVolume)))
response = AWSResponse AssignVolume
-> Logger
-> Service
-> Proxy AssignVolume
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssignVolume)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse AssignVolume
AssignVolumeResponse
AssignVolumeResponse'

instance Prelude.Hashable AssignVolume

instance Prelude.NFData AssignVolume

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

instance Core.ToJSON AssignVolume where
  toJSON :: AssignVolume -> Value
toJSON AssignVolume' {Maybe Text
Text
volumeId :: Text
instanceId :: Maybe Text
$sel:volumeId:AssignVolume' :: AssignVolume -> Text
$sel:instanceId:AssignVolume' :: AssignVolume -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"InstanceId" 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
instanceId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"VolumeId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
volumeId)
          ]
      )

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

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

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

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

instance Prelude.NFData AssignVolumeResponse