Skip to content

Terraform Provider #725

Description

@elacy

Hi,

I'm currently in the middle of rewriting my terraform provider to work with v2 and I was super excited to see that you are using GraphQL especially since I would really like the terraform provider to be able to generate new resources when they are added to the rest API but I had some problems

  • There is some metadata that is not included in the graphql schema but is included in the Model files, would it be possible to generate a json doc with all the model data included? Examples include unique_together, unique, validators, parent model
  • Some fields like InterfaceVLAN.vlanif are read only but they are not treated as read only either in the model file or in the graphql schema
  • I can't seem to get the query_params in the graphql to work

Would be interesting in hearing your take on these problems. I'm sure I can solve them myself but I don't want to go too far into a solution only to find out later it was wasted time when I could have just asked you.

btw, I am most of the way done with this work, it already generates the terraform schema, the graphql to update, delete, read. The only pieces I'm missing are:

  • Knowing how to identify each item (required during the read), I can't use id because that changes as soon as you delete something so I'm hoping to use unique_together or unique to do that.
  • Knowing how to find the parent model of a given model so that I can include their uniquely identifying properties in the child resource
  • Ensuring properties that are computed like vlanif are tagged as such

These are critical to ensuring that the terraform provider is usable.
Also I want to thank you for making this possible. I mostly just use this for my home network, but it makes it a lot easier to be sure I'm not breaking anything or leaving devices with access they shouldn't have just by looking at my terraform configuration. I can also ensure the same configuration is present in my unifi devices and in my pfsense. I think I would have given up on pfsense were it not for you work.

Activity

  1. elacy commented on Jul 17, 2025

    @elacy
    ContributorAuthor

    I took a look into how you construct the schemas I imagine the best way to do this would be to create another schema file like one of these but it just outputs the raw data I need, that would ensure that it would be possible to pull all the required data.

    Would still appreciate your opinion and if you think making the vlanif field readonly makes sense.

  2. jaredhendrickson13 commented on Jul 17, 2025

    @jaredhendrickson13
    Member

    I agree, a new custom schema would be the way to go for providing that extra metadata to clients. That should be relatively easy to implement.

    As for the vlanif field, at a glance I don't see a reason why this field shouldn't be read-only. Currently, the API will allow the client to specify a vlanif, but it will always overwrite that value with its own based on the current parent interface and VLAN tag. A PR is welcome, or you can open a separate issue for that and I can get that in the next patch.

    As for GraphQL queries, here's an example curl command to execute a query:

    curl --request POST https://localhost/api/v2/graphql \
      -u 'admin:pfsense' \
      -H 'Content-Type: application/json' \
      -d '{"query":"query {queryDiagnosticsArpTable(query_params: {ip_address__startswith: \"192.168.4\"}) { id ip_address mac_address }}"}'

    Which, for me, provides:

    {
      "data": {
        "queryDiagnosticsArpTable": [
          {
            "id": 2,
            "ip_address": "192.168.4.123",
            "mac_address": "00:50:56:02:1a:47 <small>(VMware)</small>"
          }
        ]
      }
    }

    Let me know if you still have trouble getting queries to work.

    Thanks!

  3. linked a pull request that will close this issuev2.6.0 Features & Fixes #747on Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIssues or PRs that enhance existing features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions