diff --git a/docs/data-sources/devices.md b/docs/data-sources/devices.md index e753eddd..ced93606 100644 --- a/docs/data-sources/devices.md +++ b/docs/data-sources/devices.md @@ -54,6 +54,8 @@ Read-Only: - `serial` (String) - `site_id` (Number) - `status` (String) +- `tag_ids` (List of Number) +- `tag_slugs` (List of String) - `tenant_id` (Number) diff --git a/docs/data-sources/virtual_machines.md b/docs/data-sources/virtual_machines.md index fa21d81e..4e4de0af 100644 --- a/docs/data-sources/virtual_machines.md +++ b/docs/data-sources/virtual_machines.md @@ -71,6 +71,7 @@ Read-Only: - `site_id` (Number) - `status` (String) - `tag_ids` (List of Number) +- `tag_slugs` (List of String) - `tenant_id` (Number) - `vcpus` (Number) - `vm_id` (Number) diff --git a/netbox/data_source_netbox_devices.go b/netbox/data_source_netbox_devices.go index aabac7aa..84213523 100644 --- a/netbox/data_source_netbox_devices.go +++ b/netbox/data_source_netbox_devices.go @@ -94,6 +94,20 @@ func dataSourceNetboxDevices() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + "tag_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "tag_slugs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, "tenant_id": { Type: schema.TypeInt, Computed: true, @@ -127,28 +141,22 @@ func dataSourceNetboxDevicesRead(d *schema.ResourceData, m interface{}) error { for _, f := range filterParams.List() { k := f.(map[string]interface{})["name"] v := f.(map[string]interface{})["value"] + vString := v.(string) switch k { case "asset_tag": - var assetTagString = v.(string) - params.AssetTag = &assetTagString + params.AssetTag = &vString case "cluster_id": - var clusterString = v.(string) - params.ClusterID = &clusterString + params.ClusterID = &vString case "name": - var nameString = v.(string) - params.Name = &nameString + params.Name = &vString case "region": - var regionString = v.(string) - params.Region = ®ionString + params.Region = &vString case "role_id": - var roleIdString = v.(string) - params.RoleID = &roleIdString + params.RoleID = &vString case "site_id": - var siteIdString = v.(string) - params.SiteID = &siteIdString + params.SiteID = &vString case "tenant_id": - var tenantIdString = v.(string) - params.TenantID = &tenantIdString + params.TenantID = &vString default: return fmt.Errorf("'%s' is not a supported filter parameter", k) } @@ -211,6 +219,16 @@ func dataSourceNetboxDevicesRead(d *schema.ResourceData, m interface{}) error { if device.Site != nil { mapping["site_id"] = device.Site.ID } + if device.Tags != nil { + var tagsIds []int64 + var tagsSlugs []string + for _, t := range device.Tags { + tagsIds = append(tagsIds, t.ID) + tagsSlugs = append(tagsSlugs, *t.Slug) + } + mapping["tag_ids"] = tagsIds + mapping["tag_slugs"] = tagsSlugs + } if device.Tenant != nil { mapping["tenant_id"] = device.Tenant.ID } diff --git a/netbox/data_source_netbox_virtual_machines.go b/netbox/data_source_netbox_virtual_machines.go index 99433620..6843a71c 100644 --- a/netbox/data_source_netbox_virtual_machines.go +++ b/netbox/data_source_netbox_virtual_machines.go @@ -116,6 +116,13 @@ func dataSourceNetboxVirtualMachine() *schema.Resource { Type: schema.TypeInt, }, }, + "tag_slugs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, "tenant_id": { Type: schema.TypeInt, Computed: true, @@ -249,11 +256,14 @@ func dataSourceNetboxVirtualMachineRead(d *schema.ResourceData, m interface{}) e mapping["status"] = v.Status.Value } if v.Tags != nil { - var tags []int64 + var tagsIds []int64 + var tagsSlugs []string for _, t := range v.Tags { - tags = append(tags, t.ID) + tagsIds = append(tagsIds, t.ID) + tagsSlugs = append(tagsSlugs, *t.Slug) } - mapping["tag_ids"] = tags + mapping["tag_ids"] = tagsIds + mapping["tag_slugs"] = tagsSlugs } if v.Tenant != nil { mapping["tenant_id"] = v.Tenant.ID