{-# 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.AssociateElasticIp
-- 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)
--
-- Associates one of the stack\'s registered Elastic IP addresses with a
-- specified instance. The address must first be registered with the stack
-- by calling RegisterElasticIp. 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.AssociateElasticIp
  ( -- * Creating a Request
    AssociateElasticIp (..),
    newAssociateElasticIp,

    -- * Request Lenses
    associateElasticIp_instanceId,
    associateElasticIp_elasticIp,

    -- * Destructuring the Response
    AssociateElasticIpResponse (..),
    newAssociateElasticIpResponse,
  )
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:/ 'newAssociateElasticIp' smart constructor.
data AssociateElasticIp = AssociateElasticIp'
  { -- | The instance ID.
    AssociateElasticIp -> Maybe Text
instanceId :: Prelude.Maybe Prelude.Text,
    -- | The Elastic IP address.
    AssociateElasticIp -> Text
elasticIp :: Prelude.Text
  }
  deriving (AssociateElasticIp -> AssociateElasticIp -> Bool
(AssociateElasticIp -> AssociateElasticIp -> Bool)
-> (AssociateElasticIp -> AssociateElasticIp -> Bool)
-> Eq AssociateElasticIp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateElasticIp -> AssociateElasticIp -> Bool
$c/= :: AssociateElasticIp -> AssociateElasticIp -> Bool
== :: AssociateElasticIp -> AssociateElasticIp -> Bool
$c== :: AssociateElasticIp -> AssociateElasticIp -> Bool
Prelude.Eq, ReadPrec [AssociateElasticIp]
ReadPrec AssociateElasticIp
Int -> ReadS AssociateElasticIp
ReadS [AssociateElasticIp]
(Int -> ReadS AssociateElasticIp)
-> ReadS [AssociateElasticIp]
-> ReadPrec AssociateElasticIp
-> ReadPrec [AssociateElasticIp]
-> Read AssociateElasticIp
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateElasticIp]
$creadListPrec :: ReadPrec [AssociateElasticIp]
readPrec :: ReadPrec AssociateElasticIp
$creadPrec :: ReadPrec AssociateElasticIp
readList :: ReadS [AssociateElasticIp]
$creadList :: ReadS [AssociateElasticIp]
readsPrec :: Int -> ReadS AssociateElasticIp
$creadsPrec :: Int -> ReadS AssociateElasticIp
Prelude.Read, Int -> AssociateElasticIp -> ShowS
[AssociateElasticIp] -> ShowS
AssociateElasticIp -> String
(Int -> AssociateElasticIp -> ShowS)
-> (AssociateElasticIp -> String)
-> ([AssociateElasticIp] -> ShowS)
-> Show AssociateElasticIp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateElasticIp] -> ShowS
$cshowList :: [AssociateElasticIp] -> ShowS
show :: AssociateElasticIp -> String
$cshow :: AssociateElasticIp -> String
showsPrec :: Int -> AssociateElasticIp -> ShowS
$cshowsPrec :: Int -> AssociateElasticIp -> ShowS
Prelude.Show, (forall x. AssociateElasticIp -> Rep AssociateElasticIp x)
-> (forall x. Rep AssociateElasticIp x -> AssociateElasticIp)
-> Generic AssociateElasticIp
forall x. Rep AssociateElasticIp x -> AssociateElasticIp
forall x. AssociateElasticIp -> Rep AssociateElasticIp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateElasticIp x -> AssociateElasticIp
$cfrom :: forall x. AssociateElasticIp -> Rep AssociateElasticIp x
Prelude.Generic)

-- |
-- Create a value of 'AssociateElasticIp' 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', 'associateElasticIp_instanceId' - The instance ID.
--
-- 'elasticIp', 'associateElasticIp_elasticIp' - The Elastic IP address.
newAssociateElasticIp ::
  -- | 'elasticIp'
  Prelude.Text ->
  AssociateElasticIp
newAssociateElasticIp :: Text -> AssociateElasticIp
newAssociateElasticIp Text
pElasticIp_ =
  AssociateElasticIp' :: Maybe Text -> Text -> AssociateElasticIp
AssociateElasticIp'
    { $sel:instanceId:AssociateElasticIp' :: Maybe Text
instanceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:elasticIp:AssociateElasticIp' :: Text
elasticIp = Text
pElasticIp_
    }

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

-- | The Elastic IP address.
associateElasticIp_elasticIp :: Lens.Lens' AssociateElasticIp Prelude.Text
associateElasticIp_elasticIp :: (Text -> f Text) -> AssociateElasticIp -> f AssociateElasticIp
associateElasticIp_elasticIp = (AssociateElasticIp -> Text)
-> (AssociateElasticIp -> Text -> AssociateElasticIp)
-> Lens AssociateElasticIp AssociateElasticIp Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateElasticIp' {Text
elasticIp :: Text
$sel:elasticIp:AssociateElasticIp' :: AssociateElasticIp -> Text
elasticIp} -> Text
elasticIp) (\s :: AssociateElasticIp
s@AssociateElasticIp' {} Text
a -> AssociateElasticIp
s {$sel:elasticIp:AssociateElasticIp' :: Text
elasticIp = Text
a} :: AssociateElasticIp)

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

instance Prelude.Hashable AssociateElasticIp

instance Prelude.NFData AssociateElasticIp

instance Core.ToHeaders AssociateElasticIp where
  toHeaders :: AssociateElasticIp -> [Header]
toHeaders =
    [Header] -> AssociateElasticIp -> [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.AssociateElasticIp" ::
                          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 AssociateElasticIp where
  toJSON :: AssociateElasticIp -> Value
toJSON AssociateElasticIp' {Maybe Text
Text
elasticIp :: Text
instanceId :: Maybe Text
$sel:elasticIp:AssociateElasticIp' :: AssociateElasticIp -> Text
$sel:instanceId:AssociateElasticIp' :: AssociateElasticIp -> 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
"ElasticIp" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
elasticIp)
          ]
      )

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

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

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

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

instance Prelude.NFData AssociateElasticIpResponse