e-breuninger / terraform-provider-netbox

Terraform provider to interact with Netbox
https://registry.terraform.io/providers/e-breuninger/netbox/latest/docs
Mozilla Public License 2.0
189 stars 133 forks source link

Feasibility Question: Netbox Plugins #648

Open katrinm86 opened 1 month ago

katrinm86 commented 1 month ago

Hi!

I just wanted to ask if you guys think that one could add a more or less generic plugin api or if there have already been some ideas for this (I couldn't find anything).

Our concrete use case would be Virtual Machines and the Netbox DNS Plugin (https://github.com/peteeckel/netbox-plugin-dns). So we can currently create VMs, interfaces & adresses via netbox but it would also make sense to populate the DNS records of the plugin when creating the VM.

In Ansible rudimentary interaction using query with the netbox plugin (https://docs.ansible.com/ansible/latest/collections/netbox/netbox/nb_lookup_lookup.html#ansible-collections-netbox-netbox-nb-lookup-lookup) is possible but they don't even list it in the examples (apparently you can specify a "plugin" keyword that (together with the record type) produces the right query url. But I think thats about it ...

For terraform it could look something like this in the best case

provider "netbox" {
  server_url = <>
  api_token = <>

  plugins = {
    netbox_dns = {
      netbox_dns_record = {
        id = number # implict?
        name = string
        zone_id = number
        type = optional(string, "A")
        value = string
        tags = optional(list(string), [])
      }
    }
  }
}

resource "netbox_plugin" "dns_record" {
  plugin = "netbox_dns"
  resource = "netbox_dns_record"
  data = {
    name = "my-record"
    zone_id = 10
    value = "1.2.3.4"
  }
}

But i guess it would also work if you just give it a json field or a map field thats json encoded ...

Let me know your thoughts on this :)

FlxPeters commented 1 month ago

Hey, I maintain a netbox plugin myself. From an api point of view plug-ins just provide a new endpoint or specific fields in an entity.

There are some popular plug-ins, but it's hard to tell which ones are the "good" ones. Native support in the resources are the wrong way in my opinion. But may be plugin specific resources could be a way.

katrinm86 commented 1 month ago

Thank you for your answer

Native support in the resources are the wrong way in my opinion. But may be plugin specific resources could be a way.

I don't quite understand the difference as you describe it. What does "native" here mean for you?

From what i've seen in the terraform netbox plugin they seem to rely on "github.com/fbreckle/go-netbox/netbox/client" and that in turn uses openapi to generate the clients, so they are based on the netbox api... getting plugins in there seems rather complicated but also i havent looked at openapi in ages :)

mraerino commented 3 weeks ago

i think a valid approach would be to develop separate providers for plugins. for example i've started to build a provider for the official BGP plugin and it plays pretty well with this provider: https://github.com/ffddorf/terraform-provider-netbox-bgp/