{-# 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.DnsRecord
-- 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.DnsRecord where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Route53AutoNaming.Types.RecordType

-- | A complex type that contains information about the Route 53 DNS records
-- that you want Cloud Map to create when you register an instance.
--
-- /See:/ 'newDnsRecord' smart constructor.
data DnsRecord = DnsRecord'
  { -- | The type of the resource, which indicates the type of value that Route
    -- 53 returns in response to DNS queries. You can specify values for @Type@
    -- in the following combinations:
    --
    -- -   __@A@__
    --
    -- -   __@AAAA@__
    --
    -- -   __@A@__ and __@AAAA@__
    --
    -- -   __@SRV@__
    --
    -- -   __@CNAME@__
    --
    -- If you want Cloud Map to create a Route 53 alias record when you
    -- register an instance, specify @A@ or @AAAA@ for @Type@.
    --
    -- You specify other settings, such as the IP address for @A@ and @AAAA@
    -- records, when you register an instance. For more information, see
    -- <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>.
    --
    -- The following values are supported:
    --
    -- [A]
    --     Route 53 returns the IP address of the resource in IPv4 format, such
    --     as 192.0.2.44.
    --
    -- [AAAA]
    --     Route 53 returns the IP address of the resource in IPv6 format, such
    --     as 2001:0db8:85a3:0000:0000:abcd:0001:2345.
    --
    -- [CNAME]
    --     Route 53 returns the domain name of the resource, such as
    --     www.example.com. Note the following:
    --
    --     -   You specify the domain name that you want to route traffic to
    --         when you register an instance. For more information, see
    --         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html#cloudmap-RegisterInstance-request-Attributes Attributes>
    --         in the topic
    --         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>.
    --
    --     -   You must specify @WEIGHTED@ for the value of @RoutingPolicy@.
    --
    --     -   You can\'t specify both @CNAME@ for @Type@ and settings for
    --         @HealthCheckConfig@. If you do, the request will fail with an
    --         @InvalidInput@ error.
    --
    -- [SRV]
    --     Route 53 returns the value for an @SRV@ record. The value for an
    --     @SRV@ record uses the following values:
    --
    --     @priority weight port service-hostname@
    --
    --     Note the following about the values:
    --
    --     -   The values of @priority@ and @weight@ are both set to @1@ and
    --         can\'t be changed.
    --
    --     -   The value of @port@ comes from the value that you specify for
    --         the @AWS_INSTANCE_PORT@ attribute when you submit a
    --         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>
    --         request.
    --
    --     -   The value of @service-hostname@ is a concatenation of the
    --         following values:
    --
    --         -   The value that you specify for @InstanceId@ when you
    --             register an instance.
    --
    --         -   The name of the service.
    --
    --         -   The name of the namespace.
    --
    --         For example, if the value of @InstanceId@ is @test@, the name of
    --         the service is @backend@, and the name of the namespace is
    --         @example.com@, the value of @service-hostname@ is the following:
    --
    --         @test.backend.example.com@
    --
    --     If you specify settings for an @SRV@ record, note the following:
    --
    --     -   If you specify values for @AWS_INSTANCE_IPV4@,
    --         @AWS_INSTANCE_IPV6@, or both in the @RegisterInstance@ request,
    --         Cloud Map automatically creates @A@ and\/or @AAAA@ records that
    --         have the same name as the value of @service-hostname@ in the
    --         @SRV@ record. You can ignore these records.
    --
    --     -   If you\'re using a system that requires a specific @SRV@ format,
    --         such as HAProxy, see the
    --         <https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateService.html#cloudmap-CreateService-request-Name Name>
    --         element in the documentation about @CreateService@ for
    --         information about how to specify the correct name format.
    DnsRecord -> RecordType
type' :: RecordType,
    -- | The amount of time, in seconds, that you want DNS resolvers to cache the
    -- settings for this record.
    --
    -- Alias records don\'t include a TTL because Route 53 uses the TTL for the
    -- Amazon Web Services resource that an alias record routes traffic to. If
    -- you include the @AWS_ALIAS_DNS_NAME@ attribute when you submit a
    -- <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>
    -- request, the @TTL@ value is ignored. Always specify a TTL for the
    -- service; you can use a service to register instances that create either
    -- alias or non-alias records.
    DnsRecord -> Natural
ttl :: Prelude.Natural
  }
  deriving (DnsRecord -> DnsRecord -> Bool
(DnsRecord -> DnsRecord -> Bool)
-> (DnsRecord -> DnsRecord -> Bool) -> Eq DnsRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DnsRecord -> DnsRecord -> Bool
$c/= :: DnsRecord -> DnsRecord -> Bool
== :: DnsRecord -> DnsRecord -> Bool
$c== :: DnsRecord -> DnsRecord -> Bool
Prelude.Eq, ReadPrec [DnsRecord]
ReadPrec DnsRecord
Int -> ReadS DnsRecord
ReadS [DnsRecord]
(Int -> ReadS DnsRecord)
-> ReadS [DnsRecord]
-> ReadPrec DnsRecord
-> ReadPrec [DnsRecord]
-> Read DnsRecord
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DnsRecord]
$creadListPrec :: ReadPrec [DnsRecord]
readPrec :: ReadPrec DnsRecord
$creadPrec :: ReadPrec DnsRecord
readList :: ReadS [DnsRecord]
$creadList :: ReadS [DnsRecord]
readsPrec :: Int -> ReadS DnsRecord
$creadsPrec :: Int -> ReadS DnsRecord
Prelude.Read, Int -> DnsRecord -> ShowS
[DnsRecord] -> ShowS
DnsRecord -> String
(Int -> DnsRecord -> ShowS)
-> (DnsRecord -> String)
-> ([DnsRecord] -> ShowS)
-> Show DnsRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DnsRecord] -> ShowS
$cshowList :: [DnsRecord] -> ShowS
show :: DnsRecord -> String
$cshow :: DnsRecord -> String
showsPrec :: Int -> DnsRecord -> ShowS
$cshowsPrec :: Int -> DnsRecord -> ShowS
Prelude.Show, (forall x. DnsRecord -> Rep DnsRecord x)
-> (forall x. Rep DnsRecord x -> DnsRecord) -> Generic DnsRecord
forall x. Rep DnsRecord x -> DnsRecord
forall x. DnsRecord -> Rep DnsRecord x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DnsRecord x -> DnsRecord
$cfrom :: forall x. DnsRecord -> Rep DnsRecord x
Prelude.Generic)

-- |
-- Create a value of 'DnsRecord' 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:
--
-- 'type'', 'dnsRecord_type' - The type of the resource, which indicates the type of value that Route
-- 53 returns in response to DNS queries. You can specify values for @Type@
-- in the following combinations:
--
-- -   __@A@__
--
-- -   __@AAAA@__
--
-- -   __@A@__ and __@AAAA@__
--
-- -   __@SRV@__
--
-- -   __@CNAME@__
--
-- If you want Cloud Map to create a Route 53 alias record when you
-- register an instance, specify @A@ or @AAAA@ for @Type@.
--
-- You specify other settings, such as the IP address for @A@ and @AAAA@
-- records, when you register an instance. For more information, see
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>.
--
-- The following values are supported:
--
-- [A]
--     Route 53 returns the IP address of the resource in IPv4 format, such
--     as 192.0.2.44.
--
-- [AAAA]
--     Route 53 returns the IP address of the resource in IPv6 format, such
--     as 2001:0db8:85a3:0000:0000:abcd:0001:2345.
--
-- [CNAME]
--     Route 53 returns the domain name of the resource, such as
--     www.example.com. Note the following:
--
--     -   You specify the domain name that you want to route traffic to
--         when you register an instance. For more information, see
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html#cloudmap-RegisterInstance-request-Attributes Attributes>
--         in the topic
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>.
--
--     -   You must specify @WEIGHTED@ for the value of @RoutingPolicy@.
--
--     -   You can\'t specify both @CNAME@ for @Type@ and settings for
--         @HealthCheckConfig@. If you do, the request will fail with an
--         @InvalidInput@ error.
--
-- [SRV]
--     Route 53 returns the value for an @SRV@ record. The value for an
--     @SRV@ record uses the following values:
--
--     @priority weight port service-hostname@
--
--     Note the following about the values:
--
--     -   The values of @priority@ and @weight@ are both set to @1@ and
--         can\'t be changed.
--
--     -   The value of @port@ comes from the value that you specify for
--         the @AWS_INSTANCE_PORT@ attribute when you submit a
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>
--         request.
--
--     -   The value of @service-hostname@ is a concatenation of the
--         following values:
--
--         -   The value that you specify for @InstanceId@ when you
--             register an instance.
--
--         -   The name of the service.
--
--         -   The name of the namespace.
--
--         For example, if the value of @InstanceId@ is @test@, the name of
--         the service is @backend@, and the name of the namespace is
--         @example.com@, the value of @service-hostname@ is the following:
--
--         @test.backend.example.com@
--
--     If you specify settings for an @SRV@ record, note the following:
--
--     -   If you specify values for @AWS_INSTANCE_IPV4@,
--         @AWS_INSTANCE_IPV6@, or both in the @RegisterInstance@ request,
--         Cloud Map automatically creates @A@ and\/or @AAAA@ records that
--         have the same name as the value of @service-hostname@ in the
--         @SRV@ record. You can ignore these records.
--
--     -   If you\'re using a system that requires a specific @SRV@ format,
--         such as HAProxy, see the
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateService.html#cloudmap-CreateService-request-Name Name>
--         element in the documentation about @CreateService@ for
--         information about how to specify the correct name format.
--
-- 'ttl', 'dnsRecord_ttl' - The amount of time, in seconds, that you want DNS resolvers to cache the
-- settings for this record.
--
-- Alias records don\'t include a TTL because Route 53 uses the TTL for the
-- Amazon Web Services resource that an alias record routes traffic to. If
-- you include the @AWS_ALIAS_DNS_NAME@ attribute when you submit a
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>
-- request, the @TTL@ value is ignored. Always specify a TTL for the
-- service; you can use a service to register instances that create either
-- alias or non-alias records.
newDnsRecord ::
  -- | 'type''
  RecordType ->
  -- | 'ttl'
  Prelude.Natural ->
  DnsRecord
newDnsRecord :: RecordType -> Natural -> DnsRecord
newDnsRecord RecordType
pType_ Natural
pTTL_ =
  DnsRecord' :: RecordType -> Natural -> DnsRecord
DnsRecord' {$sel:type':DnsRecord' :: RecordType
type' = RecordType
pType_, $sel:ttl:DnsRecord' :: Natural
ttl = Natural
pTTL_}

-- | The type of the resource, which indicates the type of value that Route
-- 53 returns in response to DNS queries. You can specify values for @Type@
-- in the following combinations:
--
-- -   __@A@__
--
-- -   __@AAAA@__
--
-- -   __@A@__ and __@AAAA@__
--
-- -   __@SRV@__
--
-- -   __@CNAME@__
--
-- If you want Cloud Map to create a Route 53 alias record when you
-- register an instance, specify @A@ or @AAAA@ for @Type@.
--
-- You specify other settings, such as the IP address for @A@ and @AAAA@
-- records, when you register an instance. For more information, see
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>.
--
-- The following values are supported:
--
-- [A]
--     Route 53 returns the IP address of the resource in IPv4 format, such
--     as 192.0.2.44.
--
-- [AAAA]
--     Route 53 returns the IP address of the resource in IPv6 format, such
--     as 2001:0db8:85a3:0000:0000:abcd:0001:2345.
--
-- [CNAME]
--     Route 53 returns the domain name of the resource, such as
--     www.example.com. Note the following:
--
--     -   You specify the domain name that you want to route traffic to
--         when you register an instance. For more information, see
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html#cloudmap-RegisterInstance-request-Attributes Attributes>
--         in the topic
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>.
--
--     -   You must specify @WEIGHTED@ for the value of @RoutingPolicy@.
--
--     -   You can\'t specify both @CNAME@ for @Type@ and settings for
--         @HealthCheckConfig@. If you do, the request will fail with an
--         @InvalidInput@ error.
--
-- [SRV]
--     Route 53 returns the value for an @SRV@ record. The value for an
--     @SRV@ record uses the following values:
--
--     @priority weight port service-hostname@
--
--     Note the following about the values:
--
--     -   The values of @priority@ and @weight@ are both set to @1@ and
--         can\'t be changed.
--
--     -   The value of @port@ comes from the value that you specify for
--         the @AWS_INSTANCE_PORT@ attribute when you submit a
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>
--         request.
--
--     -   The value of @service-hostname@ is a concatenation of the
--         following values:
--
--         -   The value that you specify for @InstanceId@ when you
--             register an instance.
--
--         -   The name of the service.
--
--         -   The name of the namespace.
--
--         For example, if the value of @InstanceId@ is @test@, the name of
--         the service is @backend@, and the name of the namespace is
--         @example.com@, the value of @service-hostname@ is the following:
--
--         @test.backend.example.com@
--
--     If you specify settings for an @SRV@ record, note the following:
--
--     -   If you specify values for @AWS_INSTANCE_IPV4@,
--         @AWS_INSTANCE_IPV6@, or both in the @RegisterInstance@ request,
--         Cloud Map automatically creates @A@ and\/or @AAAA@ records that
--         have the same name as the value of @service-hostname@ in the
--         @SRV@ record. You can ignore these records.
--
--     -   If you\'re using a system that requires a specific @SRV@ format,
--         such as HAProxy, see the
--         <https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateService.html#cloudmap-CreateService-request-Name Name>
--         element in the documentation about @CreateService@ for
--         information about how to specify the correct name format.
dnsRecord_type :: Lens.Lens' DnsRecord RecordType
dnsRecord_type :: (RecordType -> f RecordType) -> DnsRecord -> f DnsRecord
dnsRecord_type = (DnsRecord -> RecordType)
-> (DnsRecord -> RecordType -> DnsRecord)
-> Lens DnsRecord DnsRecord RecordType RecordType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsRecord' {RecordType
type' :: RecordType
$sel:type':DnsRecord' :: DnsRecord -> RecordType
type'} -> RecordType
type') (\s :: DnsRecord
s@DnsRecord' {} RecordType
a -> DnsRecord
s {$sel:type':DnsRecord' :: RecordType
type' = RecordType
a} :: DnsRecord)

-- | The amount of time, in seconds, that you want DNS resolvers to cache the
-- settings for this record.
--
-- Alias records don\'t include a TTL because Route 53 uses the TTL for the
-- Amazon Web Services resource that an alias record routes traffic to. If
-- you include the @AWS_ALIAS_DNS_NAME@ attribute when you submit a
-- <https://docs.aws.amazon.com/cloud-map/latest/api/API_RegisterInstance.html RegisterInstance>
-- request, the @TTL@ value is ignored. Always specify a TTL for the
-- service; you can use a service to register instances that create either
-- alias or non-alias records.
dnsRecord_ttl :: Lens.Lens' DnsRecord Prelude.Natural
dnsRecord_ttl :: (Natural -> f Natural) -> DnsRecord -> f DnsRecord
dnsRecord_ttl = (DnsRecord -> Natural)
-> (DnsRecord -> Natural -> DnsRecord)
-> Lens DnsRecord DnsRecord Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DnsRecord' {Natural
ttl :: Natural
$sel:ttl:DnsRecord' :: DnsRecord -> Natural
ttl} -> Natural
ttl) (\s :: DnsRecord
s@DnsRecord' {} Natural
a -> DnsRecord
s {$sel:ttl:DnsRecord' :: Natural
ttl = Natural
a} :: DnsRecord)

instance Core.FromJSON DnsRecord where
  parseJSON :: Value -> Parser DnsRecord
parseJSON =
    String -> (Object -> Parser DnsRecord) -> Value -> Parser DnsRecord
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DnsRecord"
      ( \Object
x ->
          RecordType -> Natural -> DnsRecord
DnsRecord'
            (RecordType -> Natural -> DnsRecord)
-> Parser RecordType -> Parser (Natural -> DnsRecord)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser RecordType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type") Parser (Natural -> DnsRecord) -> Parser Natural -> Parser DnsRecord
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TTL")
      )

instance Prelude.Hashable DnsRecord

instance Prelude.NFData DnsRecord

instance Core.ToJSON DnsRecord where
  toJSON :: DnsRecord -> Value
toJSON DnsRecord' {Natural
RecordType
ttl :: Natural
type' :: RecordType
$sel:ttl:DnsRecord' :: DnsRecord -> Natural
$sel:type':DnsRecord' :: DnsRecord -> RecordType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> RecordType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RecordType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TTL" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
ttl)
          ]
      )