github.com/StackExchange/dnscontrol/v4@v4.11.0/documentation/language-reference/top-level-functions/D_EXTEND.md (about)

     1  ---
     2  name: D_EXTEND
     3  parameters:
     4    - name
     5    - modifiers...
     6  parameter_types:
     7    name: string
     8    "modifiers...": DomainModifier[]
     9  ---
    10  
    11  `D_EXTEND` adds records (and metadata) to a domain previously defined
    12  by [`D()`](D.md). It can also be used to add subdomain records (and metadata)
    13  to a previously defined domain.
    14  
    15  The first argument is a domain name. If it exactly matches a
    16  previously defined domain, `D_EXTEND()` behaves the same as [`D()`](D.md),
    17  simply adding records as if they had been specified in the original
    18  [`D()`](D.md).
    19  
    20  If the domain name does not match an existing domain, but could be a
    21  (non-delegated) subdomain of an existing domain, the new records (and
    22  metadata) are added with the subdomain part appended to all record
    23  names (labels), and targets (as appropriate). See the examples below.
    24  
    25  Matching the domain name to previously-defined domains is done using a
    26  `longest match` algorithm.  If `domain.tld` and `sub.domain.tld` are
    27  defined as separate domains via separate [`D()`](D.md) statements, then
    28  `D_EXTEND("sub.sub.domain.tld", ...)` would match `sub.domain.tld`,
    29  not `domain.tld`.
    30  
    31  Some operators only act on an apex domain (e.g.
    32  [`CF_REDIRECT`](../domain-modifiers/CF_REDIRECT.md) and [`CF_TEMP_REDIRECT`](../domain-modifiers/CF_TEMP_REDIRECT.md)). Using them
    33  in a `D_EXTEND` subdomain may not be what you expect.
    34  
    35  {% code title="dnsconfig.js" %}
    36  ```javascript
    37  D("domain.tld", REG_MY_PROVIDER, DnsProvider(DNS),
    38    A("@", "127.0.0.1"), // domain.tld
    39    A("www", "127.0.0.2"), // www.domain.tld
    40    CNAME("a", "b"), // a.domain.tld -> b.domain.tld
    41  END);
    42  D_EXTEND("domain.tld",
    43    A("aaa", "127.0.0.3"), // aaa.domain.tld
    44    CNAME("c", "d"), // c.domain.tld -> d.domain.tld
    45  END);
    46  D_EXTEND("sub.domain.tld",
    47    A("bbb", "127.0.0.4"), // bbb.sub.domain.tld
    48    A("ccc", "127.0.0.5"), // ccc.sub.domain.tld
    49    CNAME("e", "f"), // e.sub.domain.tld -> f.sub.domain.tld
    50  END);
    51  D_EXTEND("sub.sub.domain.tld",
    52    A("ddd", "127.0.0.6"), // ddd.sub.sub.domain.tld
    53    CNAME("g", "h"), // g.sub.sub.domain.tld -> h.sub.sub.domain.tld
    54  END);
    55  D_EXTEND("sub.domain.tld",
    56    A("@", "127.0.0.7"), // sub.domain.tld
    57    CNAME("i", "j"), // i.sub.domain.tld -> j.sub.domain.tld
    58  END);
    59  ```
    60  {% endcode %}
    61  
    62  This will end up in the following modifications: (This output assumes the `--full` flag)
    63  
    64  ```text
    65  ******************** Domain: domain.tld
    66  ----- Getting nameservers from: cloudflare
    67  ----- DNS Provider: cloudflare...7 corrections
    68  #1: CREATE A aaa.domain.tld 127.0.0.3
    69  #2: CREATE A bbb.sub.domain.tld 127.0.0.4
    70  #3: CREATE A ccc.sub.domain.tld 127.0.0.5
    71  #4: CREATE A ddd.sub.sub.domain.tld 127.0.0.6
    72  #5: CREATE A sub.domain.tld 127.0.0.7
    73  #6: CREATE A www.domain.tld 127.0.0.2
    74  #7: CREATE A domain.tld 127.0.0.1
    75  #8: CREATE CNAME a.domain.tld b.domain.tld.
    76  #9: CREATE CNAME c.domain.tld d.domain.tld.
    77  #10: CREATE CNAME e.sub.domain.tld f.sub.domain.tld.
    78  #11: CREATE CNAME g.sub.sub.domain.tld h.sub.sub.domain.tld.
    79  #12: CREATE CNAME i.sub.domain.tld j.sub.domain.tld.
    80  ```
    81  
    82  ProTips: `D_EXTEND()` permits you to create very complex and
    83  sophisticated configurations, but you shouldn't. Be nice to the next
    84  person that edits the file, who may not be as expert as yourself.
    85  Enhance readability by putting any `D_EXTEND()` statements immediately
    86  after the original [`D()`](D.md), like in above example.  Avoid the temptation
    87  to obscure the addition of records to existing domains with randomly
    88  placed `D_EXTEND()` statements. Don't build up a domain using loops of
    89  `D_EXTEND()` statements. You'll be glad you didn't.