{-# 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.Route53Resolver.AssociateResolverRule
-- 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 a Resolver rule with a VPC. When you associate a rule with a
-- VPC, Resolver forwards all DNS queries for the domain name that is
-- specified in the rule and that originate in the VPC. The queries are
-- forwarded to the IP addresses for the DNS resolvers that are specified
-- in the rule. For more information about rules, see
-- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_CreateResolverRule.html CreateResolverRule>.
module Amazonka.Route53Resolver.AssociateResolverRule
  ( -- * Creating a Request
    AssociateResolverRule (..),
    newAssociateResolverRule,

    -- * Request Lenses
    associateResolverRule_name,
    associateResolverRule_resolverRuleId,
    associateResolverRule_vPCId,

    -- * Destructuring the Response
    AssociateResolverRuleResponse (..),
    newAssociateResolverRuleResponse,

    -- * Response Lenses
    associateResolverRuleResponse_resolverRuleAssociation,
    associateResolverRuleResponse_httpStatus,
  )
where

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

-- | /See:/ 'newAssociateResolverRule' smart constructor.
data AssociateResolverRule = AssociateResolverRule'
  { -- | A name for the association that you\'re creating between a Resolver rule
    -- and a VPC.
    AssociateResolverRule -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The ID of the Resolver rule that you want to associate with the VPC. To
    -- list the existing Resolver rules, use
    -- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_ListResolverRules.html ListResolverRules>.
    AssociateResolverRule -> Text
resolverRuleId :: Prelude.Text,
    -- | The ID of the VPC that you want to associate the Resolver rule with.
    AssociateResolverRule -> Text
vPCId :: Prelude.Text
  }
  deriving (AssociateResolverRule -> AssociateResolverRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateResolverRule -> AssociateResolverRule -> Bool
$c/= :: AssociateResolverRule -> AssociateResolverRule -> Bool
== :: AssociateResolverRule -> AssociateResolverRule -> Bool
$c== :: AssociateResolverRule -> AssociateResolverRule -> Bool
Prelude.Eq, ReadPrec [AssociateResolverRule]
ReadPrec AssociateResolverRule
Int -> ReadS AssociateResolverRule
ReadS [AssociateResolverRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateResolverRule]
$creadListPrec :: ReadPrec [AssociateResolverRule]
readPrec :: ReadPrec AssociateResolverRule
$creadPrec :: ReadPrec AssociateResolverRule
readList :: ReadS [AssociateResolverRule]
$creadList :: ReadS [AssociateResolverRule]
readsPrec :: Int -> ReadS AssociateResolverRule
$creadsPrec :: Int -> ReadS AssociateResolverRule
Prelude.Read, Int -> AssociateResolverRule -> ShowS
[AssociateResolverRule] -> ShowS
AssociateResolverRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateResolverRule] -> ShowS
$cshowList :: [AssociateResolverRule] -> ShowS
show :: AssociateResolverRule -> String
$cshow :: AssociateResolverRule -> String
showsPrec :: Int -> AssociateResolverRule -> ShowS
$cshowsPrec :: Int -> AssociateResolverRule -> ShowS
Prelude.Show, forall x. Rep AssociateResolverRule x -> AssociateResolverRule
forall x. AssociateResolverRule -> Rep AssociateResolverRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateResolverRule x -> AssociateResolverRule
$cfrom :: forall x. AssociateResolverRule -> Rep AssociateResolverRule x
Prelude.Generic)

-- |
-- Create a value of 'AssociateResolverRule' 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:
--
-- 'name', 'associateResolverRule_name' - A name for the association that you\'re creating between a Resolver rule
-- and a VPC.
--
-- 'resolverRuleId', 'associateResolverRule_resolverRuleId' - The ID of the Resolver rule that you want to associate with the VPC. To
-- list the existing Resolver rules, use
-- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_ListResolverRules.html ListResolverRules>.
--
-- 'vPCId', 'associateResolverRule_vPCId' - The ID of the VPC that you want to associate the Resolver rule with.
newAssociateResolverRule ::
  -- | 'resolverRuleId'
  Prelude.Text ->
  -- | 'vPCId'
  Prelude.Text ->
  AssociateResolverRule
newAssociateResolverRule :: Text -> Text -> AssociateResolverRule
newAssociateResolverRule Text
pResolverRuleId_ Text
pVPCId_ =
  AssociateResolverRule'
    { $sel:name:AssociateResolverRule' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:resolverRuleId:AssociateResolverRule' :: Text
resolverRuleId = Text
pResolverRuleId_,
      $sel:vPCId:AssociateResolverRule' :: Text
vPCId = Text
pVPCId_
    }

-- | A name for the association that you\'re creating between a Resolver rule
-- and a VPC.
associateResolverRule_name :: Lens.Lens' AssociateResolverRule (Prelude.Maybe Prelude.Text)
associateResolverRule_name :: Lens' AssociateResolverRule (Maybe Text)
associateResolverRule_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResolverRule' {Maybe Text
name :: Maybe Text
$sel:name:AssociateResolverRule' :: AssociateResolverRule -> Maybe Text
name} -> Maybe Text
name) (\s :: AssociateResolverRule
s@AssociateResolverRule' {} Maybe Text
a -> AssociateResolverRule
s {$sel:name:AssociateResolverRule' :: Maybe Text
name = Maybe Text
a} :: AssociateResolverRule)

-- | The ID of the Resolver rule that you want to associate with the VPC. To
-- list the existing Resolver rules, use
-- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_ListResolverRules.html ListResolverRules>.
associateResolverRule_resolverRuleId :: Lens.Lens' AssociateResolverRule Prelude.Text
associateResolverRule_resolverRuleId :: Lens' AssociateResolverRule Text
associateResolverRule_resolverRuleId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResolverRule' {Text
resolverRuleId :: Text
$sel:resolverRuleId:AssociateResolverRule' :: AssociateResolverRule -> Text
resolverRuleId} -> Text
resolverRuleId) (\s :: AssociateResolverRule
s@AssociateResolverRule' {} Text
a -> AssociateResolverRule
s {$sel:resolverRuleId:AssociateResolverRule' :: Text
resolverRuleId = Text
a} :: AssociateResolverRule)

-- | The ID of the VPC that you want to associate the Resolver rule with.
associateResolverRule_vPCId :: Lens.Lens' AssociateResolverRule Prelude.Text
associateResolverRule_vPCId :: Lens' AssociateResolverRule Text
associateResolverRule_vPCId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResolverRule' {Text
vPCId :: Text
$sel:vPCId:AssociateResolverRule' :: AssociateResolverRule -> Text
vPCId} -> Text
vPCId) (\s :: AssociateResolverRule
s@AssociateResolverRule' {} Text
a -> AssociateResolverRule
s {$sel:vPCId:AssociateResolverRule' :: Text
vPCId = Text
a} :: AssociateResolverRule)

instance Core.AWSRequest AssociateResolverRule where
  type
    AWSResponse AssociateResolverRule =
      AssociateResolverRuleResponse
  request :: (Service -> Service)
-> AssociateResolverRule -> Request AssociateResolverRule
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 AssociateResolverRule
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateResolverRule)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe ResolverRuleAssociation
-> Int -> AssociateResolverRuleResponse
AssociateResolverRuleResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ResolverRuleAssociation")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AssociateResolverRule where
  hashWithSalt :: Int -> AssociateResolverRule -> Int
hashWithSalt Int
_salt AssociateResolverRule' {Maybe Text
Text
vPCId :: Text
resolverRuleId :: Text
name :: Maybe Text
$sel:vPCId:AssociateResolverRule' :: AssociateResolverRule -> Text
$sel:resolverRuleId:AssociateResolverRule' :: AssociateResolverRule -> Text
$sel:name:AssociateResolverRule' :: AssociateResolverRule -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resolverRuleId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
vPCId

instance Prelude.NFData AssociateResolverRule where
  rnf :: AssociateResolverRule -> ()
rnf AssociateResolverRule' {Maybe Text
Text
vPCId :: Text
resolverRuleId :: Text
name :: Maybe Text
$sel:vPCId:AssociateResolverRule' :: AssociateResolverRule -> Text
$sel:resolverRuleId:AssociateResolverRule' :: AssociateResolverRule -> Text
$sel:name:AssociateResolverRule' :: AssociateResolverRule -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resolverRuleId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
vPCId

instance Data.ToHeaders AssociateResolverRule where
  toHeaders :: AssociateResolverRule -> ResponseHeaders
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 -> ResponseHeaders
Data.=# ( ByteString
"Route53Resolver.AssociateResolverRule" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON AssociateResolverRule where
  toJSON :: AssociateResolverRule -> Value
toJSON AssociateResolverRule' {Maybe Text
Text
vPCId :: Text
resolverRuleId :: Text
name :: Maybe Text
$sel:vPCId:AssociateResolverRule' :: AssociateResolverRule -> Text
$sel:resolverRuleId:AssociateResolverRule' :: AssociateResolverRule -> Text
$sel:name:AssociateResolverRule' :: AssociateResolverRule -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Name" 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
name,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ResolverRuleId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
resolverRuleId),
            forall a. a -> Maybe a
Prelude.Just (Key
"VPCId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
vPCId)
          ]
      )

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

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

-- | /See:/ 'newAssociateResolverRuleResponse' smart constructor.
data AssociateResolverRuleResponse = AssociateResolverRuleResponse'
  { -- | Information about the @AssociateResolverRule@ request, including the
    -- status of the request.
    AssociateResolverRuleResponse -> Maybe ResolverRuleAssociation
resolverRuleAssociation :: Prelude.Maybe ResolverRuleAssociation,
    -- | The response's http status code.
    AssociateResolverRuleResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AssociateResolverRuleResponse
-> AssociateResolverRuleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateResolverRuleResponse
-> AssociateResolverRuleResponse -> Bool
$c/= :: AssociateResolverRuleResponse
-> AssociateResolverRuleResponse -> Bool
== :: AssociateResolverRuleResponse
-> AssociateResolverRuleResponse -> Bool
$c== :: AssociateResolverRuleResponse
-> AssociateResolverRuleResponse -> Bool
Prelude.Eq, ReadPrec [AssociateResolverRuleResponse]
ReadPrec AssociateResolverRuleResponse
Int -> ReadS AssociateResolverRuleResponse
ReadS [AssociateResolverRuleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateResolverRuleResponse]
$creadListPrec :: ReadPrec [AssociateResolverRuleResponse]
readPrec :: ReadPrec AssociateResolverRuleResponse
$creadPrec :: ReadPrec AssociateResolverRuleResponse
readList :: ReadS [AssociateResolverRuleResponse]
$creadList :: ReadS [AssociateResolverRuleResponse]
readsPrec :: Int -> ReadS AssociateResolverRuleResponse
$creadsPrec :: Int -> ReadS AssociateResolverRuleResponse
Prelude.Read, Int -> AssociateResolverRuleResponse -> ShowS
[AssociateResolverRuleResponse] -> ShowS
AssociateResolverRuleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateResolverRuleResponse] -> ShowS
$cshowList :: [AssociateResolverRuleResponse] -> ShowS
show :: AssociateResolverRuleResponse -> String
$cshow :: AssociateResolverRuleResponse -> String
showsPrec :: Int -> AssociateResolverRuleResponse -> ShowS
$cshowsPrec :: Int -> AssociateResolverRuleResponse -> ShowS
Prelude.Show, forall x.
Rep AssociateResolverRuleResponse x
-> AssociateResolverRuleResponse
forall x.
AssociateResolverRuleResponse
-> Rep AssociateResolverRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateResolverRuleResponse x
-> AssociateResolverRuleResponse
$cfrom :: forall x.
AssociateResolverRuleResponse
-> Rep AssociateResolverRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateResolverRuleResponse' 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:
--
-- 'resolverRuleAssociation', 'associateResolverRuleResponse_resolverRuleAssociation' - Information about the @AssociateResolverRule@ request, including the
-- status of the request.
--
-- 'httpStatus', 'associateResolverRuleResponse_httpStatus' - The response's http status code.
newAssociateResolverRuleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateResolverRuleResponse
newAssociateResolverRuleResponse :: Int -> AssociateResolverRuleResponse
newAssociateResolverRuleResponse Int
pHttpStatus_ =
  AssociateResolverRuleResponse'
    { $sel:resolverRuleAssociation:AssociateResolverRuleResponse' :: Maybe ResolverRuleAssociation
resolverRuleAssociation =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociateResolverRuleResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the @AssociateResolverRule@ request, including the
-- status of the request.
associateResolverRuleResponse_resolverRuleAssociation :: Lens.Lens' AssociateResolverRuleResponse (Prelude.Maybe ResolverRuleAssociation)
associateResolverRuleResponse_resolverRuleAssociation :: Lens' AssociateResolverRuleResponse (Maybe ResolverRuleAssociation)
associateResolverRuleResponse_resolverRuleAssociation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResolverRuleResponse' {Maybe ResolverRuleAssociation
resolverRuleAssociation :: Maybe ResolverRuleAssociation
$sel:resolverRuleAssociation:AssociateResolverRuleResponse' :: AssociateResolverRuleResponse -> Maybe ResolverRuleAssociation
resolverRuleAssociation} -> Maybe ResolverRuleAssociation
resolverRuleAssociation) (\s :: AssociateResolverRuleResponse
s@AssociateResolverRuleResponse' {} Maybe ResolverRuleAssociation
a -> AssociateResolverRuleResponse
s {$sel:resolverRuleAssociation:AssociateResolverRuleResponse' :: Maybe ResolverRuleAssociation
resolverRuleAssociation = Maybe ResolverRuleAssociation
a} :: AssociateResolverRuleResponse)

-- | The response's http status code.
associateResolverRuleResponse_httpStatus :: Lens.Lens' AssociateResolverRuleResponse Prelude.Int
associateResolverRuleResponse_httpStatus :: Lens' AssociateResolverRuleResponse Int
associateResolverRuleResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateResolverRuleResponse' {Int
httpStatus :: Int
$sel:httpStatus:AssociateResolverRuleResponse' :: AssociateResolverRuleResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AssociateResolverRuleResponse
s@AssociateResolverRuleResponse' {} Int
a -> AssociateResolverRuleResponse
s {$sel:httpStatus:AssociateResolverRuleResponse' :: Int
httpStatus = Int
a} :: AssociateResolverRuleResponse)

instance Prelude.NFData AssociateResolverRuleResponse where
  rnf :: AssociateResolverRuleResponse -> ()
rnf AssociateResolverRuleResponse' {Int
Maybe ResolverRuleAssociation
httpStatus :: Int
resolverRuleAssociation :: Maybe ResolverRuleAssociation
$sel:httpStatus:AssociateResolverRuleResponse' :: AssociateResolverRuleResponse -> Int
$sel:resolverRuleAssociation:AssociateResolverRuleResponse' :: AssociateResolverRuleResponse -> Maybe ResolverRuleAssociation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ResolverRuleAssociation
resolverRuleAssociation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus