diff --git a/docs/data-sources/prefix.md b/docs/data-sources/prefix.md index 47d60c77..ace120ba 100644 --- a/docs/data-sources/prefix.md +++ b/docs/data-sources/prefix.md @@ -17,16 +17,21 @@ description: |- ### Optional -- `cidr` (String, Deprecated) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id` or `cidr` must be given. Conflicts with `prefix`. -- `prefix` (String) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id` or `cidr` must be given. Conflicts with `cidr`. -- `vlan_id` (Number) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id` or `cidr` must be given. -- `vlan_vid` (Number) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id` or `cidr` must be given. -- `vrf_id` (Number) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id` or `cidr` must be given. +- `cidr` (String, Deprecated) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id`, `cidr` or `tag` must be given. Conflicts with `prefix`. +- `prefix` (String) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id`, `cidr` or `tag` must be given. Conflicts with `cidr`. +- `tag` (String) Tag to include in the data source filter (must match the tag's slug). At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id`, `cidr` or `tag` must be given. +- `tag__n` (String) Tag to exclude from the data source filter (must match the tag's slug). +Refer to [Netbox's documentation](https://demo.netbox.dev/static/docs/rest-api/filtering/#lookup-expressions) +for more information on available lookup expressions. +- `vlan_id` (Number) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id`, `cidr` or `tag` must be given. +- `vlan_vid` (Number) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id`, `cidr` or `tag` must be given. +- `vrf_id` (Number) At least one of `prefix`, `vlan_vid`, `vrf_id`, `vlan_id`, `cidr` or `tag` must be given. ### Read-Only - `description` (String) - `id` (Number) The ID of this resource. - `status` (String) +- `tags` (Set of String) diff --git a/netbox/data_source_netbox_prefix.go b/netbox/data_source_netbox_prefix.go index ab017eae..708ac989 100644 --- a/netbox/data_source_netbox_prefix.go +++ b/netbox/data_source_netbox_prefix.go @@ -25,30 +25,43 @@ func dataSourceNetboxPrefix() *schema.Resource { Deprecated: "The `cidr` parameter is deprecated in favor of the canonical `prefix` attribute.", ConflictsWith: []string{"prefix"}, ValidateFunc: validation.IsCIDR, - AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr"}, + AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr", "tag"}, }, "prefix": { Type: schema.TypeString, Optional: true, ValidateFunc: validation.IsCIDR, ConflictsWith: []string{"cidr"}, - AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr"}, + AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr", "tag"}, }, "vlan_vid": { Type: schema.TypeFloat, Optional: true, - AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr"}, + AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr", "tag"}, ValidateFunc: validation.FloatBetween(1, 4094), }, "vrf_id": { Type: schema.TypeInt, Optional: true, - AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr"}, + AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr", "tag"}, }, "vlan_id": { Type: schema.TypeInt, Optional: true, - AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr"}, + AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr", "tag"}, + }, + "tag": { + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"prefix", "vlan_vid", "vrf_id", "vlan_id", "cidr", "tag"}, + Description: "Tag to include in the data source filter (must match the tag's slug).", + }, + "tag__n": { + Type: schema.TypeString, + Optional: true, + Description: `Tag to exclude from the data source filter (must match the tag's slug). +Refer to [Netbox's documentation](https://demo.netbox.dev/static/docs/rest-api/filtering/#lookup-expressions) +for more information on available lookup expressions.`, }, "status": { Type: schema.TypeString, @@ -58,6 +71,7 @@ func dataSourceNetboxPrefix() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "tags": tagsSchemaRead, }, } } @@ -92,6 +106,12 @@ func dataSourceNetboxPrefixRead(d *schema.ResourceData, m interface{}) error { if vlanVid, ok := d.Get("vlan_vid").(float64); ok && vlanVid != 0 { params.VlanVid = &vlanVid } + if tag, ok := d.Get("tag").(string); ok && tag != "" { + params.Tag = &tag + } + if tagn, ok := d.Get("tag__n").(string); ok && tagn != "" { + params.Tagn = &tagn + } res, err := api.Ipam.IpamPrefixesList(params, nil) if err != nil { @@ -108,6 +128,7 @@ func dataSourceNetboxPrefixRead(d *schema.ResourceData, m interface{}) error { d.Set("prefix", result.Prefix) d.Set("status", result.Status.Value) d.Set("description", result.Description) + d.Set("tags", getTagListFromNestedTagList(result.Tags)) if result.Vrf != nil { d.Set("vrf_id", result.Vrf.ID)