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

Data source subnet: not return gateway if using subnet_address/netmask search #42

Closed Leopol123 closed 2 years ago

Leopol123 commented 2 years ago

Affected Resource(s)

phpipam_subnet data

Terraform Version: 1.1.9 Provider Version: 1.2.12 Ipam: 1.4.4

Issue: Get gateway_id the datasource using subnet_address/subnet_mask

Terraform code

// Look up the subnet
data "phpipam_subnet" "subnet" {
  count             = var.dhcp ? 0 : 1
  subnet_address  = var.subnet
  subnet_mask     = var.netmask
}

Output:

           {
               description            = "mydescription"
               description_match      = "mydescription"
               display_hostnames      = false
               edit_date              = ""
               gateway                = {}
               gateway_id             = ""
               host_discovery_enabled = false
               id                     = "349"
               include_in_ping        = false

Expected Behavior

Receive gateway_id for this subnet.

This is working using "description match" :

// Look up the subnet
data "phpipam_subnet" "subnet" {
  section_id        = a_section_id
  description_match = "mysubnetdescription"
}

Output:

           {
               description            = "mydescription"
               description_match      = "mydescription"
               display_hostnames      = false
               edit_date              = ""
               gateway                = {}
               gateway_id             = "9620"
               host_discovery_enabled = false
               id                     = "349"
               include_in_ping        = false
lord-kyron commented 2 years ago

@pavel-z1 - what do you think of this one?

pavel-z1 commented 2 years ago

I have phpIPAM version 1.4.2

phpIPAM API does not return information about gateway. Example:

curl -X GET http://localhost/api/terraform/subnets/cidr/10.10.1.0/24/ --header "token:*******" | jq
{
  "code": 200,
  "success": true,
  "data": [
    {
      "id": "3",
      "subnet": "10.10.1.0",
      "mask": "24",
      "sectionId": "1",
      "description": "Customer 1",
      "linked_subnet": null,
      "firewallAddressObject": null,
      "vrfId": "0",
      "masterSubnetId": "2",
      "allowRequests": "1",
      "vlanId": "0",
      "showName": "1",
      "device": "0",
      "permissions": "{\"3\":\"1\",\"2\":\"2\"}",
      "pingSubnet": "0",
      "discoverSubnet": "0",
      "resolveDNS": "0",
      "DNSrecursive": "0",
      "DNSrecords": "0",
      "nameserverId": "0",
      "scanAgent": "0",
      "customer_id": null,
      "isFolder": "0",
      "isFull": "0",
      "tag": "2",
      "threshold": "0",
      "location": "0",
      "editDate": "2020-06-30 18:51:16",
      "lastScan": null,
      "lastDiscovery": null,
      "custom_CustomTestSubnets": ""
    }
  ],
  "time": 0.005
}

Seems phpIPAM has bugs, related to gateway: