diff --git a/docs/resources/tenancy_tenant_group.md b/docs/resources/tenancy_tenant_group.md index 17a3bbd01..825b15264 100644 --- a/docs/resources/tenancy_tenant_group.md +++ b/docs/resources/tenancy_tenant_group.md @@ -8,6 +8,11 @@ Manage a tenant group within Netbox. resource "netbox_tenancy_tenant_group" "tenant_group_test" { name = "TestTenantGroup" slug = "TestTenantGroup" + + 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 c12359fc9..7c9775200 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -60,6 +60,16 @@ resource "netbox_tenancy_tenant" "tenant_test" { resource "netbox_tenancy_tenant_group" "tenant_group_test" { name = "Test_TenantGroup" slug = "Test_TenantGroup" + + tag { + name = "tag1" + slug = "tag1" + } + + tag { + name = "tag2" + slug = "tag2" + } } data "netbox_dcim_site" "site_test" { diff --git a/netbox/resource_netbox_tenancy_tenant_group.go b/netbox/resource_netbox_tenancy_tenant_group.go index 672ef52c1..a3ed684eb 100644 --- a/netbox/resource_netbox_tenancy_tenant_group.go +++ b/netbox/resource_netbox_tenancy_tenant_group.go @@ -36,6 +36,22 @@ func resourceNetboxTenancyTenantGroup() *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 resourceNetboxTenancyTenantGroupCreate(d *schema.ResourceData, groupName := d.Get("name").(string) groupSlug := d.Get("slug").(string) + tags := d.Get("tag").(*schema.Set).List() newResource := &models.WritableTenantGroup{ Name: &groupName, Slug: &groupSlug, + Tags: convertTagsToNestedTags(tags), } resource := tenancy.NewTenancyTenantGroupsCreateParams().WithData(newResource) @@ -85,6 +103,10 @@ func resourceNetboxTenancyTenantGroupRead(d *schema.ResourceData, return err } + if err = d.Set("tag", convertNestedTagsToTags(resource.Tags)); err != nil { + return err + } + return nil } } @@ -103,10 +125,11 @@ func resourceNetboxTenancyTenantGroupUpdate(d *schema.ResourceData, slug := d.Get("slug").(string) params.Slug = &slug - if d.HasChange("name") { - name := d.Get("name").(string) - params.Name = &name - } + name := d.Get("name").(string) + params.Name = &name + + tags := d.Get("tag").(*schema.Set).List() + params.Tags = convertTagsToNestedTags(tags) resource := tenancy.NewTenancyTenantGroupsPartialUpdateParams().WithData( params)