diff --git a/docs/resources/ipam_vlan_group.md b/docs/resources/ipam_vlan_group.md index e6ebffd89..4fe533b16 100644 --- a/docs/resources/ipam_vlan_group.md +++ b/docs/resources/ipam_vlan_group.md @@ -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" + } } ``` @@ -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: diff --git a/examples/main.tf b/examples/main.tf index 20158f547..c12359fc9 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -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" { diff --git a/netbox/resource_netbox_ipam_vlan_group.go b/netbox/resource_netbox_ipam_vlan_group.go index 9726dab14..f0e990e94 100644 --- a/netbox/resource_netbox_ipam_vlan_group.go +++ b/netbox/resource_netbox_ipam_vlan_group.go @@ -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, + }, + }, + }, + }, }, } } @@ -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) @@ -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 } } @@ -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)