diff --git a/workspace.go b/workspace.go index df627b811..eb8f9c9b8 100644 --- a/workspace.go +++ b/workspace.go @@ -240,6 +240,9 @@ type WorkspaceListOptions struct { // Optional: A search string (comma-separated tag names) used to filter the results. Tags string `url:"search[tags],omitempty"` + // Optional: A search string (comma-separated tag names to exclude) used to filter the results. + ExcludeTags string `url:"search[exclude-tags],omitempty"` + // Optional: A list of relations to include. See available resources https://www.terraform.io/docs/cloud/api/workspaces.html#available-related-resources Include []WSIncludeOpt `url:"include,omitempty"` } diff --git a/workspace_integration_test.go b/workspace_integration_test.go index 04f0ee553..0a9dbf476 100644 --- a/workspace_integration_test.go +++ b/workspace_integration_test.go @@ -94,6 +94,28 @@ func TestWorkspacesList(t *testing.T) { assert.Equal(t, 1, wl.TotalCount) }) + t.Run("when searching using exclude-tags", func(t *testing.T) { + for wsID, tag := range map[string]string{wTest1.ID: "foo", wTest2.ID: "bar"} { + err := client.Workspaces.AddTags(ctx, wsID, WorkspaceAddTagsOptions{ + Tags: []*Tag{ + { + Name: tag, + }, + }, + }) + require.NoError(t, err) + } + + wl, err := client.Workspaces.List(ctx, orgTest.Name, &WorkspaceListOptions{ + ExcludeTags: "foo", + }) + + require.NoError(t, err) + assert.Contains(t, wl.Items[0].ID, wTest2.ID) + assert.Equal(t, 1, wl.CurrentPage) + assert.Equal(t, 1, wl.TotalCount) + }) + t.Run("when searching an unknown workspace", func(t *testing.T) { // Use a nonexisting workspace name as search attribute. The result // should be successful, but return no results.