Skip to content

Commit

Permalink
Add tag IDs support in VLAN data source
Browse files Browse the repository at this point in the history
Enhanced the VLAN data source by adding support for tag IDs. Introduced a new `tag_ids` field and adjusted the filtering logic to handle tags appropriately. This change allows users to retrieve VLAN tags as part of their configurations.
  • Loading branch information
Piethan authored and fbreckle committed Jul 30, 2024
1 parent 7a8cde5 commit 4cbb28d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion netbox/data_source_netbox_vlans.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func dataSourceNetboxVlans() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"tag_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"tenant": {
Type: schema.TypeInt,
Computed: true,
Expand All @@ -93,6 +100,7 @@ func dataSourceNetboxVlansRead(d *schema.ResourceData, m interface{}) error {

if filter, ok := d.GetOk("filter"); ok {
var filterParams = filter.(*schema.Set)
var tags []string
for _, f := range filterParams.List() {
k := f.(map[string]interface{})["name"]
v := f.(map[string]interface{})["value"]
Expand All @@ -118,6 +126,9 @@ func dataSourceNetboxVlansRead(d *schema.ResourceData, m interface{}) error {
params.GroupID = &vString
case "group_id__n":
params.GroupIDn = &vString
case "tag":
tags = append(tags, vString)
params.Tag = tags
case "tenant":
params.Tenant = &vString
case "tenant__n":
Expand Down Expand Up @@ -174,7 +185,13 @@ func dataSourceNetboxVlansRead(d *schema.ResourceData, m interface{}) error {
if v.Tenant != nil {
mapping["tenant"] = v.Tenant.ID
}

if v.Tags != nil {
var tagIDs []int64
for _, t := range v.Tags {
tagIDs = append(tagIDs, t.ID)
}
mapping["tag_ids"] = tagIDs
}
s = append(s, mapping)
}

Expand Down

0 comments on commit 4cbb28d

Please sign in to comment.