Skip to content

A function to determine automatically common reverse zones for private address ranges #100

@baryluk

Description

@baryluk

This is related to #93 , but even with that fixed I am not sure this is fully fixed problem.

The reason is that currently provider, as well as PowerDNS API requires one to specify the zone in which to create a record.

But for PTR is it really tricky.

I.e. 10.1.2.3 will be usually record 3.2.1 in zone 10.in-addr.arpa. (because 10.0.0.0/8 is usually configured like that), some one can try do something like:

resource "powerdns_record" "ptrrecord" {
  zone    = "${replace(join(".", reverse(split(".", aws_instance.instance.private_ip))), "/^\\b(?:\\d{1,3}.){3}/", "")}.in-addr.arpa."
  name    = "${join(".", reverse(split(".", aws_instance.instance.private_ip)))}.in-addr.arpa."
  type    = "PTR"
  ttl     = 60
  records = ["${var.hostname}.example.com."]
}

But then some other private zones are /16 or /24 by default, and so record needs to go to a different zone:

Example: 172.29.8.9, will go into 29.172.in-addr.arpa, because 172.16.0.0/12 is usually setup as multiple /16 zones.

resource "powerdns_record" "ptrrecord" {
  zone    = "${replace(join(".", reverse(split(".", aws_instance.instance.private_ip))), "/^\\b(?:\\d{1,3}.){2}/", "")}.in-addr.arpa."
  name    = "${join(".", reverse(split(".", aws_instance.instance.private_ip)))}.in-addr.arpa."
  type    = "PTR"
  ttl     = 60
  records = ["${var.hostname}.example.com."]
}

Similarly for 192.168.0.0/16 and 100.64.0.0/10. For the rest, I am pretty sure it is common to use /24 due to delegation reasons and it being most granular.

So, as you can see it not easy to creat a single expression for zone, that do work when one has different zone layouts. This is not the end of the worlds, but we do have some AWS, GCE, etc clusters, and some are in 172.16.0.0/12, and now we are migrating more towards 10.0.0.0/8 subnetworks (not due to space constraints, but rather to manage better IPs and prevent network collisions with some other networks we manage)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions