Skip to content

feat: added data sources for module_type, device_module_bay, netbox_device_front_port, netbox_device_rear_port #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/data-sources/device_front_port.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/fbreckle/terraform-plugin-docs
page_title: "netbox_device_front_port Data Source - terraform-provider-netbox"
subcategory: "Data Center Inventory Management (DCIM)"
description: |-
From the official documentation https://docs.netbox.dev/en/stable/models/dcim/moduletype/:
---

# netbox_device_front_port (Data Source)

From the [official documentation](https://docs.netbox.dev/en/stable/models/dcim/moduletype/):



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `device_id` (Number)
- `name` (String)

### Optional

- `color_hex` (String)
- `description` (String)
- `label` (String)
- `mark_connected` (Boolean)
- `module_id` (Number)
- `rear_port_id` (Number)
- `rear_port_position` (Number)
- `type` (String) One of [8p8c, 8p6c, 8p4c, 8p2c, 6p6c, 6p4c, 6p2c, 4p4c, 4p2c, gg45, tera-4p, tera-2p, tera-1p, 110-punch, bnc, f, n, mrj21, fc, lc, lc-pc, lc-upc, lc-apc, lsh, lsh-pc, lsh-upc, lsh-apc, mpo, mtrj, sc, sc-pc, sc-upc, sc-apc, st, cs, sn, sma-905, sma-906, urm-p2, urm-p4, urm-p8, splice, other].

### Read-Only

- `id` (Number) The ID of this resource.
- `tags` (Set of String)


36 changes: 36 additions & 0 deletions docs/data-sources/device_module_bay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
# generated by https://github.com/fbreckle/terraform-plugin-docs
page_title: "netbox_device_module_bay Data Source - terraform-provider-netbox"
subcategory: "Data Center Inventory Management (DCIM)"
description: |-
From the official documentation https://docs.netbox.dev/en/stable/models/dcim/modulebay/:
Module bays represent a space or slot within a device in which a field-replaceable module may be installed. A common example is that of a chassis-based switch such as the Cisco Nexus 9000 or Juniper EX9200. Modules in turn hold additional components that become available to the parent device.
---

# netbox_device_module_bay (Data Source)

From the [official documentation](https://docs.netbox.dev/en/stable/models/dcim/modulebay/):

> Module bays represent a space or slot within a device in which a field-replaceable module may be installed. A common example is that of a chassis-based switch such as the Cisco Nexus 9000 or Juniper EX9200. Modules in turn hold additional components that become available to the parent device.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `device_id` (Number)
- `name` (String)

### Optional

- `description` (String)
- `label` (String)
- `tags` (Set of String)

### Read-Only

- `id` (Number) The ID of this resource.


38 changes: 38 additions & 0 deletions docs/data-sources/device_rear_port.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# generated by https://github.com/fbreckle/terraform-plugin-docs
page_title: "netbox_device_rear_port Data Source - terraform-provider-netbox"
subcategory: "Data Center Inventory Management (DCIM)"
description: |-
From the official documentation https://docs.netbox.dev/en/stable/models/dcim/moduletype/:
---

# netbox_device_rear_port (Data Source)

From the [official documentation](https://docs.netbox.dev/en/stable/models/dcim/moduletype/):



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `device_id` (Number)
- `name` (String)

### Optional

- `color_hex` (String)
- `description` (String)
- `label` (String)
- `mark_connected` (Boolean)
- `module_id` (Number)
- `positions` (Number)
- `type` (String) One of [8p8c, 8p6c, 8p4c, 8p2c, 6p6c, 6p4c, 6p2c, 4p4c, 4p2c, gg45, tera-4p, tera-2p, tera-1p, 110-punch, bnc, f, n, mrj21, fc, lc, lc-pc, lc-upc, lc-apc, lsh, lsh-pc, lsh-upc, lsh-apc, mpo, mtrj, sc, sc-pc, sc-upc, sc-apc, st, cs, sn, sma-905, sma-906, urm-p2, urm-p4, urm-p8, splice, other].

### Read-Only

- `id` (Number) The ID of this resource.
- `tags` (Set of String)


39 changes: 39 additions & 0 deletions docs/data-sources/module_type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/fbreckle/terraform-plugin-docs
page_title: "netbox_module_type Data Source - terraform-provider-netbox"
subcategory: "Data Center Inventory Management (DCIM)"
description: |-
From the official documentation https://docs.netbox.dev/en/stable/models/dcim/moduletype/:
A module type represents a specific make and model of hardware component which is installable within a device's module bay and has its own child components. For example, consider a chassis-based switch or router with a number of field-replaceable line cards. Each line card has its own model number and includes a certain set of components such as interfaces. Each module type may have a manufacturer, model number, and part number assigned to it.
---

# netbox_module_type (Data Source)

From the [official documentation](https://docs.netbox.dev/en/stable/models/dcim/moduletype/):

> A module type represents a specific make and model of hardware component which is installable within a device's module bay and has its own child components. For example, consider a chassis-based switch or router with a number of field-replaceable line cards. Each line card has its own model number and includes a certain set of components such as interfaces. Each module type may have a manufacturer, model number, and part number assigned to it.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `manufacturer_id` (Number)
- `model` (String)

### Optional

- `comments` (String)
- `description` (String)
- `part_number` (String)
- `tags` (Set of String)
- `weight` (Number)
- `weight_unit` (String) One of [kg, g, lb, oz]. Required when `weight` is set.

### Read-Only

- `id` (Number) The ID of this resource.


2 changes: 1 addition & 1 deletion docs/data-sources/site.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ data "netbox_site" "get_by_slug" {

### Optional

- `asn_ids` (Set of Number)
- `facility` (String)
- `name` (String)
- `slug` (String)

### Read-Only

- `asn_ids` (Set of Number)
- `comments` (String)
- `description` (String)
- `group_id` (Number)
Expand Down
112 changes: 112 additions & 0 deletions netbox/data_source_netbox_device_front_port.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package netbox

import (
"fmt"
"strconv"

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

func dataSourceNetboxDeviceFrontPort() *schema.Resource {
return &schema.Resource{
Read: dataSourceNetboxDeviceFrontPortRead,
Description: `:meta:subcategory:Data Center Inventory Management (DCIM):From the [official documentation](https://docs.netbox.dev/en/stable/models/dcim/moduletype/):`,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"device_id": {
Type: schema.TypeInt,
Required: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "One of [8p8c, 8p6c, 8p4c, 8p2c, 6p6c, 6p4c, 6p2c, 4p4c, 4p2c, gg45, tera-4p, tera-2p, tera-1p, 110-punch, bnc, f, n, mrj21, fc, lc, lc-pc, lc-upc, lc-apc, lsh, lsh-pc, lsh-upc, lsh-apc, mpo, mtrj, sc, sc-pc, sc-upc, sc-apc, st, cs, sn, sma-905, sma-906, urm-p2, urm-p4, urm-p8, splice, other]",
},
"rear_port_id": {
Type: schema.TypeInt,
Optional: true,
},
"rear_port_position": {
Type: schema.TypeInt,
Optional: true,
},
"module_id": {
Type: schema.TypeInt,
Optional: true,
},
"label": {
Type: schema.TypeString,
Optional: true,
},
"color_hex": {
Type: schema.TypeString,
Optional: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"mark_connected": {
Type: schema.TypeBool,
Optional: true,
},
tagsKey: tagsSchemaRead,
},
}
}

func dataSourceNetboxDeviceFrontPortRead(d *schema.ResourceData, m interface{}) error {
api := m.(*client.NetBoxAPI)
params := dcim.NewDcimFrontPortsListParams()

params.Limit = int64ToPtr(2)
if deviceID, ok := d.Get("device_id").(int); ok && deviceID != 0 {
deviceID := strconv.Itoa(deviceID)
params.SetDeviceID(&deviceID)
}
if name, ok := d.Get("name").(string); ok && name != "" {
params.SetName(&name)
}

res, err := api.Dcim.DcimFrontPortsList(params, nil)
if err != nil {
return err
}

if count := *res.GetPayload().Count; count != 1 {
return fmt.Errorf("expected one `netbox_device_front_port`, but got %d", count)
}

result := res.GetPayload().Results[0]
d.SetId(strconv.FormatInt(result.ID, 10))
d.Set("device_id", result.Device.ID)
d.Set("name", result.Name)
d.Set("type", result.Type.Value)
d.Set("rear_port_id", result.RearPort.ID)
d.Set("rear_port_position", result.RearPortPosition)

if result.Module != nil {
d.Set("module_id", result.Module.ID)
} else {
d.Set("module_id", nil)
}

d.Set("label", result.Label)
d.Set("color_hex", result.Color)
d.Set("description", result.Description)
d.Set("mark_connected", result.MarkConnected)

d.Set(tagsKey, getTagListFromNestedTagList(result.Tags))

return nil
}
Loading