@@ -131,6 +131,9 @@ type Workspaces interface {
131
131
// DeleteDataRetentionPolicy deletes a workspace's data retention policy
132
132
// **Note: This functionality is only available in Terraform Enterprise.**
133
133
DeleteDataRetentionPolicy (ctx context.Context , workspaceID string ) error
134
+
135
+ // ListTagBindings lists all tag bindings associated with the workspace.
136
+ ListTagBindings (ctx context.Context , workspaceID string ) ([]* TagBinding , error )
134
137
}
135
138
136
139
// workspaces implements Workspaces.
@@ -208,6 +211,7 @@ type Workspace struct {
208
211
CurrentConfigurationVersion * ConfigurationVersion `jsonapi:"relation,current-configuration-version,omitempty"`
209
212
LockedBy * LockedByChoice `jsonapi:"polyrelation,locked-by"`
210
213
Variables []* Variable `jsonapi:"relation,vars"`
214
+ TagBindings []* TagBinding `jsonapi:"relation,tag-bindings"`
211
215
212
216
// Deprecated: Use DataRetentionPolicyChoice instead.
213
217
DataRetentionPolicy * DataRetentionPolicy
@@ -329,6 +333,10 @@ type WorkspaceListOptions struct {
329
333
// Optional: A filter string to list all the workspaces filtered by current run status.
330
334
CurrentRunStatus string `url:"filter[current-run][status],omitempty"`
331
335
336
+ // Optional: A filter string to list workspaces filtered by key/value tags.
337
+ // These are not annotated and therefore not encoded by go-querystring
338
+ TagBindings []* TagBinding
339
+
332
340
// Optional: A list of relations to include. See available resources https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces#available-related-resources
333
341
Include []WSIncludeOpt `url:"include,omitempty"`
334
342
@@ -471,6 +479,9 @@ type WorkspaceCreateOptions struct {
471
479
// Associated Project with the workspace. If not provided, default project
472
480
// of the organization will be assigned to the workspace.
473
481
Project * Project `jsonapi:"relation,project,omitempty"`
482
+
483
+ // Associated TagBindings of the workspace.
484
+ TagBindings []* TagBinding `jsonapi:"relation,tag-bindings,omitempty"`
474
485
}
475
486
476
487
// TODO: move this struct out. VCSRepoOptions is used by workspaces, policy sets, and registry modules
@@ -610,6 +621,10 @@ type WorkspaceUpdateOptions struct {
610
621
// Associated Project with the workspace. If not provided, default project
611
622
// of the organization will be assigned to the workspace
612
623
Project * Project `jsonapi:"relation,project,omitempty"`
624
+
625
+ // Associated TagBindings of the project. Note that this will replace
626
+ // all existing tag bindings.
627
+ TagBindings []* TagBinding `jsonapi:"relation,tag-bindings,omitempty"`
613
628
}
614
629
615
630
// WorkspaceLockOptions represents the options for locking a workspace.
@@ -700,8 +715,14 @@ func (s *workspaces) List(ctx context.Context, organization string, options *Wor
700
715
return nil , err
701
716
}
702
717
718
+ var tagFilters map [string ][]string
719
+ if options != nil {
720
+ tagFilters = encodeTagFiltersAsParams (options .TagBindings )
721
+ }
722
+
723
+ // Encode parameters that cannot be encoded by go-querystring
703
724
u := fmt .Sprintf ("organizations/%s/workspaces" , url .PathEscape (organization ))
704
- req , err := s .client .NewRequest ("GET" , u , options )
725
+ req , err := s .client .NewRequestWithAdditionalQueryParams ("GET" , u , options , tagFilters )
705
726
if err != nil {
706
727
return nil , err
707
728
}
@@ -715,6 +736,30 @@ func (s *workspaces) List(ctx context.Context, organization string, options *Wor
715
736
return wl , nil
716
737
}
717
738
739
+ func (s * workspaces ) ListTagBindings (ctx context.Context , workspaceID string ) ([]* TagBinding , error ) {
740
+ if ! validStringID (& workspaceID ) {
741
+ return nil , ErrInvalidWorkspaceID
742
+ }
743
+
744
+ u := fmt .Sprintf ("workspaces/%s/tag-bindings" , url .PathEscape (workspaceID ))
745
+ req , err := s .client .NewRequest ("GET" , u , nil )
746
+ if err != nil {
747
+ return nil , err
748
+ }
749
+
750
+ var list struct {
751
+ * Pagination
752
+ Items []* TagBinding
753
+ }
754
+
755
+ err = req .Do (ctx , & list )
756
+ if err != nil {
757
+ return nil , err
758
+ }
759
+
760
+ return list .Items , nil
761
+ }
762
+
718
763
// Create is used to create a new workspace.
719
764
func (s * workspaces ) Create (ctx context.Context , organization string , options WorkspaceCreateOptions ) (* Workspace , error ) {
720
765
if ! validStringID (& organization ) {
@@ -1436,7 +1481,7 @@ func (o WorkspaceCreateOptions) valid() error {
1436
1481
if o .AgentPoolID == nil && (o .ExecutionMode != nil && * o .ExecutionMode == "agent" ) {
1437
1482
return ErrRequiredAgentPoolID
1438
1483
}
1439
- if o . TriggerPrefixes != nil && len (o .TriggerPrefixes ) > 0 &&
1484
+ if len (o .TriggerPrefixes ) > 0 &&
1440
1485
o .TriggerPatterns != nil && len (o .TriggerPatterns ) > 0 {
1441
1486
return ErrUnsupportedBothTriggerPatternsAndPrefixes
1442
1487
}
@@ -1466,7 +1511,7 @@ func (o WorkspaceUpdateOptions) valid() error {
1466
1511
if o .AgentPoolID == nil && (o .ExecutionMode != nil && * o .ExecutionMode == "agent" ) {
1467
1512
return ErrRequiredAgentPoolID
1468
1513
}
1469
- if o . TriggerPrefixes != nil && len (o .TriggerPrefixes ) > 0 &&
1514
+ if len (o .TriggerPrefixes ) > 0 &&
1470
1515
o .TriggerPatterns != nil && len (o .TriggerPatterns ) > 0 {
1471
1516
return ErrUnsupportedBothTriggerPatternsAndPrefixes
1472
1517
}
0 commit comments