Skip to content

Commit

Permalink
enh: Update JSON data/resource with Netbox 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
smutel committed Aug 26, 2022
1 parent bb00911 commit adae68a
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netbox_json_dcim_inventory_item_roles_list" "test" {
limit = 0
}

output "example" {
value = jsondecode(data.netbox_json_dcim_inventory_item_roles_list.test.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netbox_json_dcim_inventory_item_templates_list" "test" {
limit = 0
}

output "example" {
value = jsondecode(data.netbox_json_dcim_inventory_item_templates_list.test.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netbox_json_dcim_module_bay_templates_list" "test" {
limit = 0
}

output "example" {
value = jsondecode(data.netbox_json_dcim_module_bay_templates_list.test.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netbox_json_dcim_module_bays_list" "test" {
limit = 0
}

output "example" {
value = jsondecode(data.netbox_json_dcim_module_bays_list.test.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netbox_json_dcim_module_types_list" "test" {
limit = 0
}

output "example" {
value = jsondecode(data.netbox_json_dcim_module_types_list.test.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netbox_json_dcim_modules_list" "test" {
limit = 0
}

output "example" {
value = jsondecode(data.netbox_json_dcim_modules_list.test.json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "netbox_json_ipam_service_templates_list" "test" {
limit = 0
}

output "example" {
value = jsondecode(data.netbox_json_ipam_service_templates_list.test.json)
}
50 changes: 50 additions & 0 deletions netbox/data_netbox_json_dcim_inventory_item_roles_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package netbox

import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
netboxclient "github.com/smutel/go-netbox/netbox/client"
"github.com/smutel/go-netbox/netbox/client/dcim"
)

func dataNetboxJSONDcimInventoryItemRolesList() *schema.Resource {
return &schema.Resource{
Description: "Get json output from the dcim_inventory_item_roles_list Netbox endpoint.",
Read: dataNetboxJSONDcimInventoryItemRolesListRead,

Schema: map[string]*schema.Schema{
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The max number of returned results. If 0 is specified, all records will be returned.",
},
"json": {
Type: schema.TypeString,
Computed: true,
Description: "JSON output of the list of objects for this Netbox endpoint.",
},
},
}
}

func dataNetboxJSONDcimInventoryItemRolesListRead(d *schema.ResourceData, m interface{}) error {
client := m.(*netboxclient.NetBoxAPI)

params := dcim.NewDcimInventoryItemRolesListParams()
limit := int64(d.Get("limit").(int))
params.Limit = &limit

list, err := client.Dcim.DcimInventoryItemRolesList(params, nil)
if err != nil {
return err
}

j, _ := json.Marshal(list.Payload.Results)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimInventoryItemRolesList")

return nil
}
50 changes: 50 additions & 0 deletions netbox/data_netbox_json_dcim_inventory_item_templates_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package netbox

import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
netboxclient "github.com/smutel/go-netbox/netbox/client"
"github.com/smutel/go-netbox/netbox/client/dcim"
)

func dataNetboxJSONDcimInventoryItemTemplatesList() *schema.Resource {
return &schema.Resource{
Description: "Get json output from the dcim_inventory_item_templates_list Netbox endpoint.",
Read: dataNetboxJSONDcimInventoryItemTemplatesListRead,

Schema: map[string]*schema.Schema{
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The max number of returned results. If 0 is specified, all records will be returned.",
},
"json": {
Type: schema.TypeString,
Computed: true,
Description: "JSON output of the list of objects for this Netbox endpoint.",
},
},
}
}

func dataNetboxJSONDcimInventoryItemTemplatesListRead(d *schema.ResourceData, m interface{}) error {
client := m.(*netboxclient.NetBoxAPI)

params := dcim.NewDcimInventoryItemTemplatesListParams()
limit := int64(d.Get("limit").(int))
params.Limit = &limit

list, err := client.Dcim.DcimInventoryItemTemplatesList(params, nil)
if err != nil {
return err
}

j, _ := json.Marshal(list.Payload.Results)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimInventoryItemTemplatesList")

return nil
}
50 changes: 50 additions & 0 deletions netbox/data_netbox_json_dcim_module_bay_templates_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package netbox

import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
netboxclient "github.com/smutel/go-netbox/netbox/client"
"github.com/smutel/go-netbox/netbox/client/dcim"
)

func dataNetboxJSONDcimModuleBayTemplatesList() *schema.Resource {
return &schema.Resource{
Description: "Get json output from the dcim_module_bay_templates_list Netbox endpoint.",
Read: dataNetboxJSONDcimModuleBayTemplatesListRead,

Schema: map[string]*schema.Schema{
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The max number of returned results. If 0 is specified, all records will be returned.",
},
"json": {
Type: schema.TypeString,
Computed: true,
Description: "JSON output of the list of objects for this Netbox endpoint.",
},
},
}
}

func dataNetboxJSONDcimModuleBayTemplatesListRead(d *schema.ResourceData, m interface{}) error {
client := m.(*netboxclient.NetBoxAPI)

params := dcim.NewDcimModuleBayTemplatesListParams()
limit := int64(d.Get("limit").(int))
params.Limit = &limit

list, err := client.Dcim.DcimModuleBayTemplatesList(params, nil)
if err != nil {
return err
}

j, _ := json.Marshal(list.Payload.Results)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimModuleBayTemplatesList")

return nil
}
50 changes: 50 additions & 0 deletions netbox/data_netbox_json_dcim_module_bays_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package netbox

import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
netboxclient "github.com/smutel/go-netbox/netbox/client"
"github.com/smutel/go-netbox/netbox/client/dcim"
)

func dataNetboxJSONDcimModuleBaysList() *schema.Resource {
return &schema.Resource{
Description: "Get json output from the dcim_module_bays_list Netbox endpoint.",
Read: dataNetboxJSONDcimModuleBaysListRead,

Schema: map[string]*schema.Schema{
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The max number of returned results. If 0 is specified, all records will be returned.",
},
"json": {
Type: schema.TypeString,
Computed: true,
Description: "JSON output of the list of objects for this Netbox endpoint.",
},
},
}
}

func dataNetboxJSONDcimModuleBaysListRead(d *schema.ResourceData, m interface{}) error {
client := m.(*netboxclient.NetBoxAPI)

params := dcim.NewDcimModuleBaysListParams()
limit := int64(d.Get("limit").(int))
params.Limit = &limit

list, err := client.Dcim.DcimModuleBaysList(params, nil)
if err != nil {
return err
}

j, _ := json.Marshal(list.Payload.Results)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimModuleBaysList")

return nil
}
50 changes: 50 additions & 0 deletions netbox/data_netbox_json_dcim_module_types_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package netbox

import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
netboxclient "github.com/smutel/go-netbox/netbox/client"
"github.com/smutel/go-netbox/netbox/client/dcim"
)

func dataNetboxJSONDcimModuleTypesList() *schema.Resource {
return &schema.Resource{
Description: "Get json output from the dcim_module_types_list Netbox endpoint.",
Read: dataNetboxJSONDcimModuleTypesListRead,

Schema: map[string]*schema.Schema{
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The max number of returned results. If 0 is specified, all records will be returned.",
},
"json": {
Type: schema.TypeString,
Computed: true,
Description: "JSON output of the list of objects for this Netbox endpoint.",
},
},
}
}

func dataNetboxJSONDcimModuleTypesListRead(d *schema.ResourceData, m interface{}) error {
client := m.(*netboxclient.NetBoxAPI)

params := dcim.NewDcimModuleTypesListParams()
limit := int64(d.Get("limit").(int))
params.Limit = &limit

list, err := client.Dcim.DcimModuleTypesList(params, nil)
if err != nil {
return err
}

j, _ := json.Marshal(list.Payload.Results)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimModuleTypesList")

return nil
}
50 changes: 50 additions & 0 deletions netbox/data_netbox_json_dcim_modules_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package netbox

import (
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
netboxclient "github.com/smutel/go-netbox/netbox/client"
"github.com/smutel/go-netbox/netbox/client/dcim"
)

func dataNetboxJSONDcimModulesList() *schema.Resource {
return &schema.Resource{
Description: "Get json output from the dcim_modules_list Netbox endpoint.",
Read: dataNetboxJSONDcimModulesListRead,

Schema: map[string]*schema.Schema{
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The max number of returned results. If 0 is specified, all records will be returned.",
},
"json": {
Type: schema.TypeString,
Computed: true,
Description: "JSON output of the list of objects for this Netbox endpoint.",
},
},
}
}

func dataNetboxJSONDcimModulesListRead(d *schema.ResourceData, m interface{}) error {
client := m.(*netboxclient.NetBoxAPI)

params := dcim.NewDcimModulesListParams()
limit := int64(d.Get("limit").(int))
params.Limit = &limit

list, err := client.Dcim.DcimModulesList(params, nil)
if err != nil {
return err
}

j, _ := json.Marshal(list.Payload.Results)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimModulesList")

return nil
}
Loading

0 comments on commit adae68a

Please sign in to comment.