{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:instanceId:AssociateElasticIp' :: Maybe Text
instanceId = 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 :: Lens' AssociateElasticIp (Maybe Text)
associateElasticIp_instanceId = 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 :: Lens' AssociateElasticIp Text
associateElasticIp_elasticIp = 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 :: (Service -> Service)
-> AssociateElasticIp -> Request AssociateElasticIp
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateElasticIp
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateElasticIp)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AssociateElasticIpResponse
AssociateElasticIpResponse'

instance Prelude.Hashable AssociateElasticIp where
  hashWithSalt :: Int -> AssociateElasticIp -> Int
hashWithSalt Int
_salt AssociateElasticIp' {Maybe Text
Text
elasticIp :: Text
instanceId :: Maybe Text
$sel:elasticIp:AssociateElasticIp' :: AssociateElasticIp -> Text
$sel:instanceId:AssociateElasticIp' :: AssociateElasticIp -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
instanceId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
elasticIp

instance Prelude.NFData AssociateElasticIp where
  rnf :: AssociateElasticIp -> ()
rnf AssociateElasticIp' {Maybe Text
Text
elasticIp :: Text
instanceId :: Maybe Text
$sel:elasticIp:AssociateElasticIp' :: AssociateElasticIp -> Text
$sel:instanceId:AssociateElasticIp' :: AssociateElasticIp -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
instanceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
elasticIp

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"InstanceId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
instanceId,
            forall a. a -> Maybe a
Prelude.Just (Key
"ElasticIp" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
elasticIp)
          ]
      )

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

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

-- | /See:/ 'newAssociateElasticIpResponse' smart constructor.
data AssociateElasticIpResponse = AssociateElasticIpResponse'
  {
  }
  deriving (AssociateElasticIpResponse -> AssociateElasticIpResponse -> Bool
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]
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
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.
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 where
  rnf :: AssociateElasticIpResponse -> ()
rnf AssociateElasticIpResponse
_ = ()