BunnyWay / terraform-provider-bunnynet

bunny.net Terraform provider
https://registry.terraform.io/providers/BunnyWay/bunnynet
Mozilla Public License 2.0
6 stars 1 forks source link

Feature: DNS Zone as data source #9

Closed kgierke closed 1 month ago

kgierke commented 2 months ago

Description

I'd would be great if I can use the DNS Zone as data resource in my projects, without importing the DNS Zone as resource in all projects.

Current solution

For every projects which uses DNS Entries I have to import the DNS Zone manually to create DNS Records.

Preferred solution

Having the DNS Zone as "Data Resource" to avoid importing the zone into every project. Preferably referred to by domain name. See Hetzner DNS as example: https://registry.terraform.io/providers/timohirt/hetznerdns/latest/docs/data-sources/hetznerdns_zone

data "hetznerdns_zone" "zone1" {
    name = "zone1.online"
}
rafael-at-bunny commented 2 months ago

Hi!

Do you have a specific reason to not import the Bunny DNS records into your terraform plan? I'm trying to see if there is an use case in which importing the records isn't feasible.

Thank you.

rafael-at-bunny commented 1 month ago

Hi.

We found a couple of use cases internally, so I went ahead and built it. bunnynet_dns_zone and bunnynet_dns_record data sources are available in v0.3.12.

Example:

data "bunnynet_dns_zone" "example" {
  domain = "example.org"
}

output "nameservers" {
  value = [
    data.bunnynet_dns_zone.example.nameserver1,
    data.bunnynet_dns_zone.example.nameserver2,
  ]
}

data "bunnynet_dns_record" "A1" {
  id = 123
  zone = data.bunnynet_dns_zone.example.id
  type = "A"
  name = "www"
}

data "bunnynet_dns_record" "A2" {
  id = 456
  zone = data.bunnynet_dns_zone.example.id
  type = "A"
  name = "www"
}

output "ips" {
  value = [
    data.bunnynet_dns_record.A1.value,
    data.bunnynet_dns_record.A2.value,
  ]
}

Output:

data.bunnynet_dns_zone.example: Reading...
data.bunnynet_dns_zone.example: Read complete after 0s
data.bunnynet_dns_record.A1: Reading...
data.bunnynet_dns_record.A2: Reading...
data.bunnynet_dns_record.A1: Read complete after 0s [name=www]
data.bunnynet_dns_record.A2: Read complete after 0s [name=www]

Changes to Outputs:
  + nameservers = [
      + "kiki.bunny.net",
      + "coco.bunny.net",
    ]
  + www_ips     = [
      + "192.0.2.6",
      + "192.0.2.99",
    ]

Let us know if you find any issues.

Thank you.

kgierke commented 1 month ago

Awesome, I just wanted to reply, that my use case might be more about perception than actual technical requirement. In my case I develop multiple micro services which each manage their own infrastructure with terraform, so in that case the basic DNS Zone isn't really a resource of that specific micro service. Hope that makes sense 😄

Anyways thanks for implementing it so fast!