Skip to content
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
10 changes: 5 additions & 5 deletions docs/data-sources/vlan_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ data "netbox_vlan_group" "example3" {

### Optional

- `name` (String) At least one of `name`, `slug` or `scope_type` must be given.
- `scope_id` (Number) Required when `scope_type` is set.
- `scope_type` (String) Valid values are `dcim.location`, `dcim.site`, `dcim.sitegroup`, `dcim.region`, `dcim.rack`, `virtualization.cluster` and `virtualization.clustergroup`. At least one of `name`, `slug` or `scope_type` must be given.
- `slug` (String) At least one of `name`, `slug` or `scope_type` must be given.
- `id` (String) At least one of `id`, `name`, `slug` or `scope_type` must be given.
- `name` (String) At least one of `id`, `name`, `slug` or `scope_type` must be given.
- `scope_id` (String) Required when `scope_type` is set.
- `scope_type` (String) Valid values are `dcim.location`, `dcim.site`, `dcim.sitegroup`, `dcim.region`, `dcim.rack`, `virtualization.cluster` and `virtualization.clustergroup`. At least one of `id`, `name`, `slug` or `scope_type` must be given.
- `slug` (String) At least one of `id`, `name`, `slug` or `scope_type` must be given.

### Read-Only

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


58 changes: 58 additions & 0 deletions docs/data-sources/vlan_groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# generated by https://github.com/fbreckle/terraform-plugin-docs
page_title: "netbox_vlan_groups Data Source - terraform-provider-netbox"
subcategory: "IP Address Management (IPAM)"
description: |-

---

# netbox_vlan_groups (Data Source)





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

### Optional

- `filter` (Block Set) (see [below for nested schema](#nestedblock--filter))
- `limit` (Number) Defaults to `0`.

### Read-Only

- `id` (String) The ID of this resource.
- `vlan_groups` (List of Object) (see [below for nested schema](#nestedatt--vlan_groups))

<a id="nestedblock--filter"></a>
### Nested Schema for `filter`

Required:

- `name` (String)
- `value` (String)


<a id="nestedatt--vlan_groups"></a>
### Nested Schema for `vlan_groups`

Read-Only:

- `description` (String)
- `id` (Number)
- `name` (String)
- `ranges` (List of Object) (see [below for nested schema](#nestedobjatt--vlan_groups--ranges))
- `slug` (String)
- `tag_ids` (List of Number)
- `used` (Number)

<a id="nestedobjatt--vlan_groups--ranges"></a>
### Nested Schema for `vlan_groups.ranges`

Read-Only:

- `end` (Number)
- `start` (Number)


29 changes: 21 additions & 8 deletions netbox/data_source_netbox_vlan_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ func dataSourceNetboxVlanGroup() *schema.Resource {
Read: dataSourceNetboxVlanGroupRead,
Description: `:meta:subcategory:IP Address Management (IPAM):`,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
AtLeastOneOf: []string{"id", "name", "slug", "scope_type"},
},
"name": {
Type: schema.TypeString,
Computed: true,
Optional: true,
AtLeastOneOf: []string{"name", "slug", "scope_type"},
AtLeastOneOf: []string{"id", "name", "slug", "scope_type"},
},
"slug": {
Type: schema.TypeString,
Optional: true,
Computed: true,
AtLeastOneOf: []string{"name", "slug", "scope_type"},
AtLeastOneOf: []string{"id", "name", "slug", "scope_type"},
},
"scope_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(resourceNetboxVlanGroupScopeTypeOptions, false),
Description: buildValidValueDescription(resourceNetboxVlanGroupScopeTypeOptions),
AtLeastOneOf: []string{"name", "slug", "scope_type"},
AtLeastOneOf: []string{"id", "name", "slug", "scope_type"},
},
"scope_id": {
Type: schema.TypeInt,
Type: schema.TypeString,
Comment on lines -37 to +43
Copy link
Author

@hp197 hp197 Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: true,
RequiredWith: []string{"scope_type"},
},
Expand All @@ -55,17 +61,21 @@ func dataSourceNetboxVlanGroupRead(d *schema.ResourceData, m interface{}) error
params := ipam.NewIpamVlanGroupsListParams()

params.Limit = int64ToPtr(2)

if id, ok := d.Get("id").(string); ok && id != "" {
params.ID = strToPtr(id)
}
if name, ok := d.Get("name").(string); ok && name != "" {
params.Name = &name
params.Name = strToPtr(name)
}
if slug, ok := d.Get("slug").(string); ok && slug != "" {
params.Slug = &slug
params.Slug = strToPtr(slug)
}
if scopeType, ok := d.Get("scope_type").(string); ok && scopeType != "" {
params.SetScopeType(&scopeType)
params.ScopeType = strToPtr(scopeType)
}
if scopeID, ok := d.Get("scope_id").(string); ok && scopeID != "" {
params.SetScopeID(params.ScopeID)
params.ScopeID = strToPtr(scopeID)
}

res, err := api.Ipam.IpamVlanGroupsList(params, nil)
Expand All @@ -82,9 +92,12 @@ func dataSourceNetboxVlanGroupRead(d *schema.ResourceData, m interface{}) error

result := res.GetPayload().Results[0]
d.SetId(strconv.FormatInt(result.ID, 10))
d.Set("id", strconv.FormatInt(result.ID, 10))
d.Set("name", result.Name)
d.Set("slug", result.Slug)
d.Set("vlan_count", result.VlanCount)
d.Set("description", result.Description)
d.Set("scope_id", strconv.FormatInt(*result.ScopeID, 10))
d.Set("scope_type", result.ScopeType)
return nil
}
13 changes: 13 additions & 0 deletions netbox/data_source_netbox_vlan_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func TestAccNetboxVlanGroupDataSource_basic(t *testing.T) {
Config: setUp + testAccNetboxVlanGroupDataNoResult,
ExpectError: regexp.MustCompile("no vlan group found matching filter"),
},
{
Config: setUp + testAccNetboxVlanGroupDataByID("netbox_vlan_group.test", "id"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.netbox_vlan_group.test", "id", "netbox_vlan_group.test", "id"),
),
},
{
Config: setUp + testAccNetboxVlanGroupDataByName(testName),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -109,6 +115,13 @@ data "netbox_vlan_group" "no_result" {
name = "_no_result_"
}`

func testAccNetboxVlanGroupDataByID(resourceRef, field string) string {
return fmt.Sprintf(`
data "netbox_vlan_group" "test" {
id = %[1]s.%[2]s
}`, resourceRef, field)
}

func testAccNetboxVlanGroupDataByName(testName string) string {
return fmt.Sprintf(`
data "netbox_vlan_group" "test" {
Expand Down
Loading