lord-kyron / terraform-provider-phpipam

Terrform provider for PHPIPAM
https://registry.terraform.io/providers/lord-kyron/phpipam/latest
Apache License 2.0
54 stars 30 forks source link

Add calculation property to Subnet Data Source #35

Closed Gianlu closed 2 years ago

Gianlu commented 2 years ago

Hi, Is it possible to add the calculation property to Subnet exported attributes? They are available via raw rest api. It will be nice to have also the nameseververs composite property: now we have the id but there is no data source to obtain this information.

Thank you

pavel-z1 commented 2 years ago

Hi @Gianlu

This terraform provider use API that provide phpipam software to receive data. In the phpIPAM documentation https://phpipam.net/api/api_documentation/ I don't see any API method to get nameserver hostname or fqdn. If you have information about such API endpoint please show some example.

What did you mean by calculation property to Subnet exported attributes?

Gianlu commented 2 years ago

Hi, when I query subnet endpoint (subnets/169/ for example) in my phpipam install, it returns this structure:

{
    "id":  "169",
    "subnet":  "10.31.10.0",
    "mask":  "24",
    "sectionId":  "3",
    "description":  "My-Subnet",
    "firewallAddressObject":  null,
    "vrfId":  "0",
    "masterSubnetId":  "107",
    "allowRequests":  "0",
    "vlanId":  "105",
    "showName":  "1",
    "device":  "0",
    "permissions":  "{\"4\":\"1\",\"6\":\"2\",\"7\":\"1\",\"8\":\"2\"}",
    "pingSubnet":  "0",
    "discoverSubnet":  "0",
    "DNSrecursive":  "0",
    "nameserverId":  "2",
    "DNSrecords":  "0",
    "scanAgent":  "0",
    "isFolder":  "0",
    "isFull":  "0",
    "tag":  "2",
    "editDate":  "2021-08-16 10:30:08",
    "threshold":  "0",
    "linked_subnet":  null,
    "location":  "9"
    "nameservers":  {
                        "id":  "2",
                        "name":  "Zone DNS",
                        "namesrv1":  "10.31.31.10;10.31.31.11",
                        "description":  null,
                        "permissions":  "3;17",
                        "editDate":  "2021-05-07 14:21:08"
                    },
    "gatewayId":  "8086",
    "gateway":  {
                    "ip_addr":  "10.31.10.254",
                    "id":  "8086"
                },
    "calculation":  {
                        "Type":  "IPv4",
                        "IP address":  "/",
                        "Network":  "10.31.10.0",
                        "Broadcast":  "10.31.10.255",
                        "Subnet bitmask":  "24",
                        "Subnet netmask":  "255.255.255.0",
                        "Subnet wildcard":  "0.0.0.255",
                        "Min host IP":  "10.31.10.1",
                        "Max host IP":  "10.31.10.254",
                        "Number of hosts":  254,
                        "Subnet Class":  "private A"
                    },
    "links":  [
                  {
                      "rel":  "self",
                      "href":  "/api/appssl/subnets/169/",
                      "methods":  "GET POST DELETE PATCH"
                  },
                  {
                      "rel":  "addresses",
                      "href":  "/api/appssl/subnets/169/addresses/",
                      "methods":  "GET"
                  },
                  {
                      "rel":  "addresses/{ip}",
                      "href":  "/api/appssl/subnets/169/addresses/{ip}/",
                      "methods":  "GET"
                  },
                  {
                      "rel":  "usage",
                      "href":  "/api/appssl/subnets/169/usage/",
                      "methods":  "GET"
                  },
                  {
                      "rel":  "first_free",
                      "href":  "/api/appssl/subnets/169/first_free/",
                      "methods":  "GET"
                  },
                  {
                      "rel":  "slaves",
                      "href":  "/api/appssl/subnets/169/slaves/",
                      "methods":  "GET"
                  },
                  {
                      "rel":  "slaves_recursive",
                      "href":  "/api/appssl/subnets/169/slaves_recursive/",
                      "methods":  "GET"
                  },
                  {
                      "rel":  "truncate",
                      "href":  "/api/appssl/subnets/169/truncate/",
                      "methods":  "DELETE"
                  },
                  {
                      "rel":  "permissions",
                      "href":  "/api/appssl/subnets/169/permissions/",
                      "methods":  "PATCH"
                  },
                  {
                      "rel":  "resize",
                      "href":  "/api/appssl/subnets/169/resize/",
                      "methods":  "PATCH"
                  },
                  {
                      "rel":  "split",
                      "href":  "/api/appssl/subnets/169/split/",
                      "methods":  "PATCH"
                  }
              ]
}

In this provider, we have nameserverId but in API response I see a structure with DNS IP (nameservers). Moreover I have a structure calculation with some network info.

For nameservers IP, the endpoint is tools/nameservers/{nameserverid}/ (you can find it in section 3.9 of phpipam doc). I hope it helps and thank you for your project.

Bye

poulpreben commented 2 years ago

I have submitted a PR for the phpipam-go-sdk project to include this information: https://github.com/pavel-z1/phpipam-sdk-go/pull/5

pavel-z1 commented 2 years ago

Hi @poulpreben Thank you for pull request.