\fBTYPE\fP the query type (A, PTR, ... can be ANY to match all types).
.IP\(bu4
\fBZONE\fP the zone scope(s) for this template. Defaults to the server zones.
.IP\(bu4
\fBREGEX\fP Go regexp
\[la]https://golang.org/pkg/regexp/\[ra] that are matched against the incoming question name. Specifying no regex matches everything (default: \fB\fC.*\fR). First matching regex wins.
.IP\(bu4
\fB\fCanswer|additional|authority\fR\fBRR\fP A RFC 1035
\[la]https://tools.ietf.org/html/rfc1035#section-5\[ra] style resource record fragment
built by a Go template
\[la]https://golang.org/pkg/text/template/\[ra] that contains the reply.
.IP\(bu4
\fB\fCrcode\fR\fBCODE\fP A response code (\fB\fCNXDOMAIN, SERVFAIL, ...\fR). The default is \fB\fCSUCCESS\fR.
.IP\(bu4
\fB\fCupstream\fR defines the upstream resolvers used for resolving CNAMEs. CoreDNS will resolve CNAMEs against itself.
.IP\(bu4
\fB\fCfallthrough\fR Continue with the next plugin if the zone matched but no regex matched.
If specific zones are listed (for example \fB\fCin-addr.arpa\fR and \fB\fCip6.arpa\fR), then only queries for
those zones will be subject to fallthrough.
.PP
At least one \fB\fCanswer\fR or \fB\fCrcode\fR directive is needed (e.g. \fB\fCrcode NXDOMAIN\fR).
.PP
Also see
\[la]#also-see\[ra] contains an additional reading list.
.SHTEMPLATES
.PP
Each resource record is a full-featured Go template
\[la]https://golang.org/pkg/text/template/\[ra] with the following predefined data
.IP\(bu4
\fB\fC.Zone\fR the matched zone string (e.g. \fB\fCexample.\fR).
.IP\(bu4
\fB\fC.Name\fR the query name, as a string (lowercased).
.IP\(bu4
\fB\fC.Class\fR the query class (usually \fB\fCIN\fR).
.IP\(bu4
\fB\fC.Type\fR the RR type requested (e.g. \fB\fCPTR\fR).
.IP\(bu4
\fB\fC.Match\fR an array of all matches. \fB\fCindex .Match 0\fR refers to the whole match.
.IP\(bu4
\fB\fC.Group\fR a map of the named capture groups.
.IP\(bu4
\fB\fC.Message\fR the complete incoming DNS message.
.IP\(bu4
\fB\fC.Question\fR the matched question section.
.PP
The output of the template must be a RFC 1035
\[la]https://tools.ietf.org/html/rfc1035\[ra] style resource record (commonly referred to as a "zone file").
.PP
\fBWARNING\fP there is a syntactical problem with Go templates and CoreDNS config files. Expressions
like \fB\fC{{$var}}\fR will be interpreted as a reference to an environment variable by CoreDNS (and
Caddy) while \fB\fC{{ $var }}\fR will work. See Bugs
\[la]#bugs\[ra] and corefile(5).
.SHMETRICS
.PP
If monitoring is enabled (via the \fIprometheus\fP directive) then the following metrics are exported:
.IP\(bu4
\fB\fCcoredns_template_matches_total{server, regex}\fR the total number of matched requests by regex.
.IP\(bu4
\fB\fCcoredns_template_template_failures_total{server, regex,section,template}\fR the number of times the Go templating failed. Regex, section and template label values can be used to map the error back to the config file.
.IP\(bu4
\fB\fCcoredns_template_rr_failures_total{server, regex,section,template}\fR the number of times the templated resource record was invalid and could not be parsed. Regex, section and template label values can be used to map the error back to the config file.
.PP
Both failure cases indicate a problem with the template configuration. The \fB\fCserver\fR label indicates
the server incrementing the metric, see the \fImetrics\fP plugin for details.