Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing data source for PTR record generation #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johannwagner
Copy link

@johannwagner johannwagner commented Jul 4, 2022

This introduces a data source, which can generate a PTR record on the fly with an ip address as parameter. This fixes #93.

Example:

data "powerdns_ptr" "foo" {
    ip_address = "1.2.3.4"
}

resource "powerdns_record" "foobar" {
  zone    = "in-addr.arpa."
  name    = data.powerdns_ptr.foo.ptr_address
  type    = "PTR"
  ttl     = 300
  records = ["www.example.com."]
}

@johannwagner
Copy link
Author

I would also like to add documentation, since this is a user-facing feature, but currently there are no instructions on building or using the documentation part.

addressStringSplitted := strings.Split(ipAddress4.String(), ".")
reverseAddressParts := make([]string, 0)
for i := len(addressStringSplitted) - 1; i >= 0; i-- {
reverseAddressParts = append(reverseAddressParts, addressStringSplitted[i])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to use append. We know what is the length of ipv4 and ipv6 address (I would not even assert on that, as you can trust net.Parse to work if there was no error), so array can be preallocated with exact size, and reversing done without append. (there is more you can do, but that might be overkill here).

Also in the IPv4 you use make, but in IPv6 you don't.

@baryluk
Copy link

baryluk commented Mar 16, 2024

LGTM in general, but the looping can be done simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native tooling for creating reverse ptr records from a given IPv4 or v6 address
2 participants