Skip to content

Commit

Permalink
feat: Add tag parameter to vlan group resource
Browse files Browse the repository at this point in the history
  • Loading branch information
smutel committed May 17, 2022
1 parent 6047bd5 commit eb88a02
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/resources/ipam_vlan_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Manage a vlan group within Netbox.
resource "netbox_ipam_vlan_group" "vlan_group_test" {
name = "TestVlanGroup"
slug = "TestVlanGroup"
tag {
name = "tag1"
slug = "tag1"
}
}
```

Expand All @@ -17,6 +22,10 @@ The following arguments are supported:
* ``name`` - (Required) The name for this object.
* ``slug`` - (Required) The slug for this object.

The ``tag`` block (optional) supports:
* ``name`` - (Required) Name of the existing tag to associate with this resource.
* ``slug`` - (Required) Slug of the existing tag to associate with this resource.

## Attributes Reference

In addition to the above arguments, the following attributes are exported:
Expand Down
10 changes: 10 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ data "netbox_dcim_site" "site_test" {
resource "netbox_ipam_vlan_group" "vlan_group_test" {
name = "Test_VlanGroup"
slug = "Test_VlanGroup"

tag {
name = "tag1"
slug = "tag1"
}

tag {
name = "tag2"
slug = "tag2"
}
}

data "netbox_ipam_role" "vlan_role_production" {
Expand Down
25 changes: 25 additions & 0 deletions netbox/resource_netbox_ipam_vlan_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ func resourceNetboxIpamVlanGroup() *schema.Resource {
regexp.MustCompile("^[-a-zA-Z0-9_]{1,50}$"),
"Must be like ^[-a-zA-Z0-9_]{1,50}$"),
},
"tag": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"slug": {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
}
}
Expand All @@ -46,10 +62,12 @@ func resourceNetboxIpamVlanGroupCreate(d *schema.ResourceData,

groupName := d.Get("name").(string)
groupSlug := d.Get("slug").(string)
tags := d.Get("tag").(*schema.Set).List()

newResource := &models.VLANGroup{
Name: &groupName,
Slug: &groupSlug,
Tags: convertTagsToNestedTags(tags),
}

resource := ipam.NewIpamVlanGroupsCreateParams().WithData(newResource)
Expand Down Expand Up @@ -84,6 +102,10 @@ func resourceNetboxIpamVlanGroupRead(d *schema.ResourceData,
return err
}

if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil {
return err
}

return nil
}
}
Expand All @@ -104,6 +126,9 @@ func resourceNetboxIpamVlanGroupUpdate(d *schema.ResourceData,
slug := d.Get("slug").(string)
params.Slug = &slug

tags := d.Get("tag").(*schema.Set).List()
params.Tags = convertTagsToNestedTags(tags)

resource := ipam.NewIpamVlanGroupsPartialUpdateParams().WithData(
params)

Expand Down

0 comments on commit eb88a02

Please sign in to comment.