{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Route53AutoNaming.Types.DnsConfig
-- 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)
module Amazonka.Route53AutoNaming.Types.DnsConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Route53AutoNaming.Types.DnsRecord
import Amazonka.Route53AutoNaming.Types.RoutingPolicy

-- | A complex type that contains information about the Amazon Route 53 DNS
-- records that you want Cloud Map to create when you register an instance.
--
-- /See:/ 'newDnsConfig' smart constructor.
data DnsConfig = DnsConfig'
  { -- | The routing policy that you want to apply to all Route 53 DNS records
    -- that Cloud Map creates when you register an instance and specify this
    -- service.
    --
    -- If you want to use this service to register instances that create alias
    -- records, specify @WEIGHTED@ for the routing policy.
    --
    -- You can specify the following values:
    --
    -- [MULTIVALUE]
    --     If you define a health check for the service and the health check is
    --     healthy, Route 53 returns the applicable value for up to eight
    --     instances.
    --
    --     For example, suppose that the service includes configurations for
    --     one @A@ record and a health check. You use the service to register
    --     10 instances. Route 53 responds to DNS queries with IP addresses for
    --     up to eight healthy instances. If fewer than eight instances are
    --     healthy, Route 53 responds to every DNS query with the IP addresses
    --     for all of the healthy instances.
    --
    --     If you don\'t define a health check for the service, Route 53
    --     assumes that all instances are healthy and returns the values for up
    --     to eight instances.
    --
    --     For more information about the multivalue routing policy, see
    --     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-multivalue Multivalue Answer Routing>
    --     in the /Route 53 Developer Guide/.
    --
    -- [WEIGHTED]
    --     Route 53 returns the applicable value from one randomly selected
    --     instance from among the instances that you registered using the same
    --     service. Currently, all records have the same weight, so you can\'t
    --     route more or less traffic to any instances.
    --
    --     For example, suppose that the service includes configurations for
    --     one @A@ record and a health check. You use the service to register
    --     10 instances. Route 53 responds to DNS queries with the IP address
    --     for one randomly selected instance from among the healthy instances.
    --     If no instances are healthy, Route 53 responds to DNS queries as if
    --     all of the instances were healthy.
    --
    --     If you don\'t define a health check for the service, Route 53
    --     assumes that all instances are healthy and returns the applicable
    --     value for one randomly selected instance.
    --
    --     For more information about the weighted routing policy, see
    --     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted Weighted Routing>
    --     in the /Route 53 Developer Guide/.
    DnsConfig -> Maybe RoutingPolicy
routingPolicy :: Prelude.Maybe RoutingPolicy,
    -- | The ID of the namespace to use for DNS configuration.
    DnsConfig -> Maybe Text
namespaceId :: Prelude.Maybe Prelude.Text,
    -- | An array that contains one @DnsRecord@ object for each Route 53 DNS
    -- record that you want Cloud Map to create when you register an instance.
    DnsConfig -> [DnsRecord]
dnsRecords :: [DnsRecord]
  }
  deriving (DnsConfig -> DnsConfig -> Bool
(DnsConfig -> DnsConfig -> Bool)
-> (DnsConfig -> DnsConfig -> Bool) -> Eq DnsConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DnsConfig -> DnsConfig -> Bool
$c/= :: DnsConfig -> DnsConfig -> Bool
== :: DnsConfig -> DnsConfig -> Bool
$c== :: DnsConfig -> DnsConfig -> Bool
Prelude.Eq, ReadPrec [DnsConfig]
ReadPrec DnsConfig
Int -> ReadS DnsConfig
ReadS [DnsConfig]
(Int -> ReadS DnsConfig)
-> ReadS [DnsConfig]
-> ReadPrec DnsConfig
-> ReadPrec [DnsConfig]
-> Read DnsConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DnsConfig]
$creadListPrec :: ReadPrec [DnsConfig]
readPrec :: ReadPrec DnsConfig
$creadPrec :: ReadPrec DnsConfig
readList :: ReadS [DnsConfig]
$creadList :: ReadS [DnsConfig]
readsPrec :: Int -> ReadS DnsConfig
$creadsPrec :: Int -> ReadS DnsConfig
Prelude.Read, Int -> DnsConfig -> ShowS
[DnsConfig] -> ShowS
DnsConfig -> String
(Int -> DnsConfig -> ShowS)
-> (DnsConfig -> String)
-> ([DnsConfig] -> ShowS)
-> Show DnsConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DnsConfig] -> ShowS
$cshowList :: [DnsConfig] -> ShowS
show :: DnsConfig -> String
$cshow :: DnsConfig -> String
showsPrec :: Int -> DnsConfig -> ShowS
$cshowsPrec :: Int -> DnsConfig -> ShowS
Prelude.Show, (forall x. DnsConfig -> Rep DnsConfig x)
-> (forall x. Rep DnsConfig x -> DnsConfig) -> Generic DnsConfig
forall x. Rep DnsConfig x -> DnsConfig
forall x. DnsConfig -> Rep DnsConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DnsConfig x -> DnsConfig
$cfrom :: forall x. DnsConfig -> Rep DnsConfig x
Prelude.Generic)

-- |
-- Create a value of 'DnsConfig' 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:
--
-- 'routingPolicy', 'dnsConfig_routingPolicy' - The routing policy that you want to apply to all Route 53 DNS records
-- that Cloud Map creates when you register an instance and specify this
-- service.
--
-- If you want to use this service to register instances that create alias
-- records, specify @WEIGHTED@ for the routing policy.
--
-- You can specify the following values:
--
-- [MULTIVALUE]
--     If you define a health check for the service and the health check is
--     healthy, Route 53 returns the applicable value for up to eight
--     instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with IP addresses for
--     up to eight healthy instances. If fewer than eight instances are
--     healthy, Route 53 responds to every DNS query with the IP addresses
--     for all of the healthy instances.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the values for up
--     to eight instances.
--
--     For more information about the multivalue routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-multivalue Multivalue Answer Routing>
--     in the /Route 53 Developer Guide/.
--
-- [WEIGHTED]
--     Route 53 returns the applicable value from one randomly selected
--     instance from among the instances that you registered using the same
--     service. Currently, all records have the same weight, so you can\'t
--     route more or less traffic to any instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with the IP address
--     for one randomly selected instance from among the healthy instances.
--     If no instances are healthy, Route 53 responds to DNS queries as if
--     all of the instances were healthy.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the applicable
--     value for one randomly selected instance.
--
--     For more information about the weighted routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted Weighted Routing>
--     in the /Route 53 Developer Guide/.
--
-- 'namespaceId', 'dnsConfig_namespaceId' - The ID of the namespace to use for DNS configuration.
--
-- 'dnsRecords', 'dnsConfig_dnsRecords' - An array that contains one @DnsRecord@ object for each Route 53 DNS
-- record that you want Cloud Map to create when you register an instance.
newDnsConfig ::
  DnsConfig
newDnsConfig :: DnsConfig
newDnsConfig =
  DnsConfig' :: Maybe RoutingPolicy -> Maybe Text -> [DnsRecord] -> DnsConfig
DnsConfig'
    { $sel:routingPolicy:DnsConfig' :: Maybe RoutingPolicy
routingPolicy = Maybe RoutingPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:namespaceId:DnsConfig' :: Maybe Text
namespaceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:dnsRecords:DnsConfig' :: [DnsRecord]
dnsRecords = [DnsRecord]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The routing policy that you want to apply to all Route 53 DNS records
-- that Cloud Map creates when you register an instance and specify this
-- service.
--
-- If you want to use this service to register instances that create alias
-- records, specify @WEIGHTED@ for the routing policy.
--
-- You can specify the following values:
--
-- [MULTIVALUE]
--     If you define a health check for the service and the health check is
--     healthy, Route 53 returns the applicable value for up to eight
--     instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with IP addresses for
--     up to eight healthy instances. If fewer than eight instances are
--     healthy, Route 53 responds to every DNS query with the IP addresses
--     for all of the healthy instances.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the values for up
--     to eight instances.
--
--     For more information about the multivalue routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-multivalue Multivalue Answer Routing>
--     in the /Route 53 Developer Guide/.
--
-- [WEIGHTED]
--     Route 53 returns the applicable value from one randomly selected
--     instance from among the instances that you registered using the same
--     service. Currently, all records have the same weight, so you can\'t
--     route more or less traffic to any instances.
--
--     For example, suppose that the service includes configurations for
--     one @A@ record and a health check. You use the service to register
--     10 instances. Route 53 responds to DNS queries with the IP address
--     for one randomly selected instance from among the healthy instances.
--     If no instances are healthy, Route 53 responds to DNS queries as if
--     all of the instances were healthy.
--
--     If you don\'t define a health check for the service, Route 53
--     assumes that all instances are healthy and returns the applicable
--     value for one randomly selected instance.
--
--     For more information about the weighted routing policy, see
--     <https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted Weighted Routing>
--     in the /Route 53 Developer Guide/.
dnsConfig_routingPolicy :: Lens.Lens' DnsConfig (Prelude.Maybe RoutingPolicy)
dnsConfig_routingPolicy :: (Maybe RoutingPolicy -> f (Maybe RoutingPolicy))
-> DnsConfig -> f DnsConfig
dnsConfig_routingPolicy = (DnsConfig -> Maybe RoutingPolicy)
-> (DnsConfig -> Maybe RoutingPolicy -> DnsConfig)
-> Lens
     DnsConfig DnsConfig (Maybe RoutingPolicy) (Maybe RoutingPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsConfig' {Maybe RoutingPolicy
routingPolicy :: Maybe RoutingPolicy
$sel:routingPolicy:DnsConfig' :: DnsConfig -> Maybe RoutingPolicy
routingPolicy} -> Maybe RoutingPolicy
routingPolicy) (\s :: DnsConfig
s@DnsConfig' {} Maybe RoutingPolicy
a -> DnsConfig
s {$sel:routingPolicy:DnsConfig' :: Maybe RoutingPolicy
routingPolicy = Maybe RoutingPolicy
a} :: DnsConfig)

-- | The ID of the namespace to use for DNS configuration.
dnsConfig_namespaceId :: Lens.Lens' DnsConfig (Prelude.Maybe Prelude.Text)
dnsConfig_namespaceId :: (Maybe Text -> f (Maybe Text)) -> DnsConfig -> f DnsConfig
dnsConfig_namespaceId = (DnsConfig -> Maybe Text)
-> (DnsConfig -> Maybe Text -> DnsConfig)
-> Lens DnsConfig DnsConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsConfig' {Maybe Text
namespaceId :: Maybe Text
$sel:namespaceId:DnsConfig' :: DnsConfig -> Maybe Text
namespaceId} -> Maybe Text
namespaceId) (\s :: DnsConfig
s@DnsConfig' {} Maybe Text
a -> DnsConfig
s {$sel:namespaceId:DnsConfig' :: Maybe Text
namespaceId = Maybe Text
a} :: DnsConfig)

-- | An array that contains one @DnsRecord@ object for each Route 53 DNS
-- record that you want Cloud Map to create when you register an instance.
dnsConfig_dnsRecords :: Lens.Lens' DnsConfig [DnsRecord]
dnsConfig_dnsRecords :: ([DnsRecord] -> f [DnsRecord]) -> DnsConfig -> f DnsConfig
dnsConfig_dnsRecords = (DnsConfig -> [DnsRecord])
-> (DnsConfig -> [DnsRecord] -> DnsConfig)
-> Lens DnsConfig DnsConfig [DnsRecord] [DnsRecord]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsConfig' {[DnsRecord]
dnsRecords :: [DnsRecord]
$sel:dnsRecords:DnsConfig' :: DnsConfig -> [DnsRecord]
dnsRecords} -> [DnsRecord]
dnsRecords) (\s :: DnsConfig
s@DnsConfig' {} [DnsRecord]
a -> DnsConfig
s {$sel:dnsRecords:DnsConfig' :: [DnsRecord]
dnsRecords = [DnsRecord]
a} :: DnsConfig) (([DnsRecord] -> f [DnsRecord]) -> DnsConfig -> f DnsConfig)
-> (([DnsRecord] -> f [DnsRecord]) -> [DnsRecord] -> f [DnsRecord])
-> ([DnsRecord] -> f [DnsRecord])
-> DnsConfig
-> f DnsConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([DnsRecord] -> f [DnsRecord]) -> [DnsRecord] -> f [DnsRecord]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON DnsConfig where
  parseJSON :: Value -> Parser DnsConfig
parseJSON =
    String -> (Object -> Parser DnsConfig) -> Value -> Parser DnsConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DnsConfig"
      ( \Object
x ->
          Maybe RoutingPolicy -> Maybe Text -> [DnsRecord] -> DnsConfig
DnsConfig'
            (Maybe RoutingPolicy -> Maybe Text -> [DnsRecord] -> DnsConfig)
-> Parser (Maybe RoutingPolicy)
-> Parser (Maybe Text -> [DnsRecord] -> DnsConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe RoutingPolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RoutingPolicy")
            Parser (Maybe Text -> [DnsRecord] -> DnsConfig)
-> Parser (Maybe Text) -> Parser ([DnsRecord] -> DnsConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NamespaceId")
            Parser ([DnsRecord] -> DnsConfig)
-> Parser [DnsRecord] -> Parser DnsConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [DnsRecord])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DnsRecords" Parser (Maybe [DnsRecord]) -> [DnsRecord] -> Parser [DnsRecord]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [DnsRecord]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable DnsConfig

instance Prelude.NFData DnsConfig

instance Core.ToJSON DnsConfig where
  toJSON :: DnsConfig -> Value
toJSON DnsConfig' {[DnsRecord]
Maybe Text
Maybe RoutingPolicy
dnsRecords :: [DnsRecord]
namespaceId :: Maybe Text
routingPolicy :: Maybe RoutingPolicy
$sel:dnsRecords:DnsConfig' :: DnsConfig -> [DnsRecord]
$sel:namespaceId:DnsConfig' :: DnsConfig -> Maybe Text
$sel:routingPolicy:DnsConfig' :: DnsConfig -> Maybe RoutingPolicy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RoutingPolicy" Text -> RoutingPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RoutingPolicy -> Pair) -> Maybe RoutingPolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RoutingPolicy
routingPolicy,
            (Text
"NamespaceId" 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
namespaceId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DnsRecords" Text -> [DnsRecord] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [DnsRecord]
dnsRecords)
          ]
      )