DNS Zone

Overview

The DNS Zone module contains two types of builders - dnsZone, used to create DNS Zones, and ___Record (like cnameRecord, aRecord, ..), used to create DNS Records sets. It supports most record types (except CAA) and has specific builders for every record type.

  • DNS Zone (Microsoft.Network/dnsZones)
  • A Record (Microsoft.Network/dnsZones/A)
  • AAAA Record (Microsoft.Network/dnsZones/AAAA)
  • CNAME Record (Microsoft.Network/dnsZones/CNAME)
  • TXT Record (Microsoft.Network/dnsZones/TXT)
  • MX Record (Microsoft.Network/dnsZones/MX)
  • NS Record (Microsoft.Network/dnsZones/NS)
  • PTR Record (Microsoft.Network/dnsZones/PTR)
  • SOA Record (Microsoft.Network/dnsZones/SOA)
  • SRV Record (Microsoft.Network/dnsZones/SRV)
  • Private Zone Virtual Network Link (Microsoft.Network/privateDnsZones/virtualNetworkLinks)

SOA records

You can only have one SOA record and it is always created alongside a DNS zone, whether you specify it or not.

You can use the builder provided by Farmer to edit any of its properties. You should not, however, edit the host as this is set automatically by Azure.

Ideally, it just wouldn’t be exposed, however contrary to the official documentation Azure rejects the ARM record if it is absent. For this reason, if you wish to use the SOA builder it is recommended to first deploy your DNS Zone without it, copy the generated SOA host from the portal and then finally paste it into the Farmer builder’s host parameter.

NS Records

An NS record is automatically added to every DNS zone at the apex (@) containing the name of the Azure DNS servers assigned to the zone.

You can modify certain properties of it, but not others.

If you wish to create a new NS record set, you must give it a name field.

TODO

The following items are currently unsupported:

  • CAA records
  • Virtual network support for Private Zones
  • Tags

DNS Zone Builder Keywords

KeywordPurpose
nameSets the name of the domain.
depends_onDeploy this DNS zone after another resource is successfully deployed.
zone_typeSets the zone type.
add_recordsAdds DNS Zone records (see below).

Each Record type has its own custom builder. All builders share the following common keywords:

KeywordPurpose
nameSets the name of the record set (default to @).
depends_onDeploy this DNS record after another resource is successfully deployed.
ttlSets the time-to-live of the record set.
zone_typeWhen set to Private changes the resource type from Microsoft.Network/dnsZone/x to Microsoft.Network/privateDnsZone/x. (default to Public)
link_to_dns_zoneAdd the record to a DNS zone in the same deployment.
link_to_unmanaged_dns_zoneAdd the record to an existing DNS zone.

In addition, each record builder has its own custom keywords:

A Record Builder Keywords

KeywordPurpose
add_ipv4_addressesAdd IPv4 addresses to this record set.
target_resourceA reference to an azure resource from where the dns resource value is taken.

AAAA Record Builder Keywords

KeywordPurpose
add_ipv6_addressesAdd IPv6 addresses to this record set.
target_resourceA reference to an azure resource from where the dns resource value is taken.

CNAME Record Builder Keywords

KeywordPurpose
cnameSets the canonical name for this CNAME record.
target_resourceA reference to an azure resource from where the dns resource value is taken.

TXT Record Builder Keywords

KeywordPurpose
add_valuesAdd TXT values to this record set.

MX Record Builder Keywords

KeywordPurpose
add_valuesAdd MX values to the record set.

NS Record Builder Keywords

KeywordPurpose
add_nsd_namesAdd NS values to this record set. (Subdomain NameServers)
add_nsd_referenceReference NS records from another DNS Zone. (Subdomain NameServers)

PTR Record Builder Keywords

KeywordPurpose
add_ptrd_namesAdd PTR names to this record set.

SRV Record Builder Keywords

KeywordPurpose
nameThe service and protocol must be specified as part of the record set name, prefixed with underscores.
add_valuesAdd Farmer.DNS.SrvRecord values to this record set.

SOA Record Builder Keywords

KeywordPurpose
hostSets the host name for the record
emailSets the email for the record
expire_timeSets the expire time name for the record in seconds
minimum_ttlSets the minimum time to live for the record in seconds
refresh_timeSets the refresh time for the record in seconds
retry_timeSets the retry time for the record in seconds
serial_numberSets the serial number for the record
KeywordPurpose
private_dns_zoneSets the DNS Zone to provide DNS resolution for a virtual network.
link_to_private_dns_zoneLinks to an existing DNS Zone to provide DNS resolution for a virtual network.
registration_enabledAutomatically create DNS records for virtual machines in the linked virtual network.
virtual_network_idThe resource id of the virtual network the DNS Zone that will use the DNS Zone for resolution.

Configuration Members

MemberPurpose
NameServersGets the ARM expression path to the NameServers. When evaluated, will return a JSON array as string.

Example

#r "nuget: Farmer"

open Farmer
open Farmer.Builders

let dns = dnsZone {
    name "farmer.com"
    zone_type Dns.Public
    add_records [
        cnameRecord {
            name "www2"
            ttl 3600
            cname "farmer.github.com"
        }
        aRecord {
            name "aName"
            ttl 7200
            add_ipv4_addresses [ "192.168.0.1"; "192.168.0.2" ]
        }
        aaaaRecord {
            name "aaaaName"
            ttl 7200
            add_ipv6_addresses [ "2001:0db8:85a3:0000:0000:8a2e:0370:7334" ]
        }
        txtRecord {
            name "txtName"
            ttl 3600
            add_values [ "v=spf1 include:spf.protection.outlook.com -all" ]
        }
        mxRecord {
            name "mxName"
            ttl 7200
            add_values [
                0, "farmer-com.mail.protection.outlook.com";
                1, "farmer2-com.mail.protection.outlook.com";
            ]
        }
        soaRecord {
            name "soaName"
            host "ns1-09.azure-dns.com."
            ttl 3600
            email "test.microsoft.com"
            serial_number 1L
            minimum_ttl 300L
            refresh_time 3600L
            retry_time 300L
            expire_time 2419200L
        }
        srvRecord {
            name "_sip._tcp.name"
            ttl 3600
            add_values [
                { Priority = Some 100
                Weight = Some 1
                Port = Some 5061
                Target = Some "farmer.online.com."}
            ]
        }
    ]
}

let deployment = arm {
    location Location.NorthEurope
    add_resource dns
}

deployment
|> Writer.quickWrite "dns-example"