summaryrefslogtreecommitdiff
path: root/manifests/record.pp
blob: aaac0e0aee7e7edcf023a54bf893d71bf76a9d05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# @summary A single DNS record
#
# @example
#   dns::record { 'A www.example.com':
#     zone  => 'example.com',
#     key   => 'www',
#     value => '203.0.113.4',
#   }
#
# @param type
#   Record type (A, AAAA, ...)
# @param cls
#   DNS class type (IN, HS, CH, HS)
# @param ttl
#   TTL for record.
# @param duplicate
#   Allow multiple records with the same name and class.
#   Most record types only allow one value, but some allow multiple.
#   Setting this to true allows for multiple. This value is
#   automatically true for TXT, MX & NS.
# @param zone
#   Name of the zone this record belongs to.
# @param value
#   Record content.
#   Syntax depends on `type`.
#   Some record types have extra processing.
#   TXT splits data into chunks of 255 characters (TODO shouldn't
#   this be bytes) and the surrounds each chunk with quotation marks.
# @param key
#   DNS key. Will be treated as absolute if ending with a period, or
#   relative to the zone if not. '@' for the "empty" key.
#   TODO tests for above?
define dns::record (
  String $zone,
  Dns::Rr $type,
  String $value,
  Dns::Class $cls = 'IN',
  String $key = '@',
  Optional[Dns::Ttl] $ttl = undef,
  Boolean $duplicate = false,
) {
  $zone_ = dns::ensure_ending_period($zone)

  $allow_duplicate = case $type {
    'TXT',
    'MX',
    'NS': {
      true
    }
    default: {
      false
    }
  }

  $value_ = case $type {
    'TXT': {
      $value.slice(255).map |$x| { "\"${x.join()}\"" }.join(' ')
    }
    default: {
      $value
    }
  }

  dns_record2 { $name:
    type            => $type,
    value           => $value_,
    cls             => $cls,
    zone            => $zone,
    ttl             => $ttl,
    key             => $key,
    named_checkzone => $dns::checkzone,
  }
}