Skip to content
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

Add tag IDs support in VLAN data source #621

Merged
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
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 @@ -172,7 +183,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
Loading