@@ -54,13 +54,17 @@ var (
5454 getTfxClientContext (),
5555 * viperString ("search" ),
5656 * viperString ("repository" ),
57- * viperString ("run-status" ))
57+ * viperString ("run-status" ),
58+ * viperString ("project-id" ),
59+ )
5860 } else {
5961 return workspaceList (
6062 getTfxClientContext (),
6163 * viperString ("search" ),
6264 * viperString ("repository" ),
63- * viperString ("run-status" ))
65+ * viperString ("run-status" ),
66+ * viperString ("project-id" ),
67+ )
6468 }
6569 },
6670 }
@@ -83,6 +87,8 @@ func init() {
8387 workspaceListCmd .Flags ().StringP ("search" , "s" , "" , "Search string for Workspace Name (optional)." )
8488 workspaceListCmd .Flags ().StringP ("repository" , "r" , "" , "Filter on Repository Identifier (i.e. username/repo_name) (optional)." )
8589 workspaceListCmd .Flags ().String ("run-status" , "" , "Filter on current run status (optional)." )
90+ workspaceListCmd .Flags ().String ("project-id" , "" , "Filter on project ID (optional)." )
91+
8692 workspaceListCmd .Flags ().BoolP ("all" , "a" , false , "List All Organizations Workspaces (optional)." )
8793
8894 // `tfx workspace show`
@@ -94,14 +100,15 @@ func init() {
94100 workspaceCmd .AddCommand (workspaceShowCmd )
95101}
96102
97- func workspaceListAllForOrganization (c TfxClientContext , orgName string , searchString string ) ([]* tfe.Workspace , error ) {
103+ func workspaceListAllForOrganization (c TfxClientContext , orgName string , searchString string , projectID string ) ([]* tfe.Workspace , error ) {
98104 allItems := []* tfe.Workspace {}
99105 opts := tfe.WorkspaceListOptions {
100106 ListOptions : tfe.ListOptions {PageNumber : 1 , PageSize : 100 },
101107 Search : searchString ,
102108 // Tags: "",
103109 // ExcludeTags: "",
104- Include : []tfe.WSIncludeOpt {"organization" , "current_run" },
110+ ProjectID : projectID ,
111+ Include : []tfe.WSIncludeOpt {"organization" , "current_run" },
105112 }
106113 for {
107114 items , err := c .Client .Workspaces .List (c .Context , orgName , & opts )
@@ -163,9 +170,9 @@ func workspaceListAllRemoteStateConsumers(c TfxClientContext, workspaceId string
163170 return allItems , nil
164171}
165172
166- func workspaceList (c TfxClientContext , searchString string , repoIdentifier string , runStatus string ) error {
173+ func workspaceList (c TfxClientContext , searchString string , repoIdentifier string , runStatus string , projectID string ) error {
167174 o .AddMessageUserProvided ("List Workspaces for Organization:" , c .OrganizationName )
168- items , err := workspaceListAllForOrganization (c , c .OrganizationName , searchString )
175+ items , err := workspaceListAllForOrganization (c , c .OrganizationName , searchString , projectID )
169176 if err != nil {
170177 return errors .Wrap (err , "failed to list workspaces" )
171178 }
@@ -180,7 +187,7 @@ func workspaceList(c TfxClientContext, searchString string, repoIdentifier strin
180187 o .AddFormattedMessageCalculated ("Found %d Filtered Workspaces" , len (items ))
181188 }
182189
183- o .AddTableHeader ("Name" , "Id" , "Current Run Created" , "Status" , "Repository" , "Locked" )
190+ o .AddTableHeader ("Name" , "Id" , "Resource Count" , " Current Run Created" , "Status" , "Repository" , "Locked" )
184191 for _ , i := range items {
185192 cr_created_at := ""
186193 cr_status := ""
@@ -193,13 +200,13 @@ func workspaceList(c TfxClientContext, searchString string, repoIdentifier strin
193200 ws_repo = i .VCSRepo .DisplayIdentifier
194201 }
195202
196- o .AddTableRows (i .Name , i .ID , cr_created_at , cr_status , ws_repo , i .Locked )
203+ o .AddTableRows (i .Name , i .ID , i . ResourceCount , cr_created_at , cr_status , ws_repo , i .Locked )
197204 }
198205
199206 return nil
200207}
201208
202- func workspaceListAll (c TfxClientContext , searchString string , repoIdentifier string , runStatus string ) error {
209+ func workspaceListAll (c TfxClientContext , searchString string , repoIdentifier string , runStatus string , projectID string ) error {
203210 o .AddMessageUserProvided ("List Workspaces for all available Organizations" , "" )
204211 orgs , err := organizationListAll (c )
205212 if err != nil {
@@ -208,7 +215,7 @@ func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier st
208215
209216 var allWorkspaceList []* tfe.Workspace
210217 for _ , v := range orgs {
211- workspaceList , err := workspaceListAllForOrganization (c , v .Name , searchString )
218+ workspaceList , err := workspaceListAllForOrganization (c , v .Name , searchString , projectID )
212219 if err != nil {
213220 logError (err , "failed to list workspaces for organization" )
214221 }
@@ -229,7 +236,7 @@ func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier st
229236 o .AddFormattedMessageCalculated ("Found %d Filtered Workspaces" , len (allWorkspaceList ))
230237 }
231238
232- o .AddTableHeader ("Organization" , "Name" , "Id" , "Current Run Created" , "Status" , "Repository" , "Locked" )
239+ o .AddTableHeader ("Organization" , "Name" , "Id" , "Resource Count" , " Current Run Created" , "Status" , "Repository" , "Locked" )
233240 for _ , i := range allWorkspaceList {
234241 cr_created_at := ""
235242 cr_status := ""
@@ -242,7 +249,7 @@ func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier st
242249 ws_repo = i .VCSRepo .DisplayIdentifier
243250 }
244251
245- o .AddTableRows (i .Organization .Name , i .Name , i .ID , cr_created_at , cr_status , ws_repo , i .Locked )
252+ o .AddTableRows (i .Organization .Name , i .Name , i .ID , i . ResourceCount , cr_created_at , cr_status , ws_repo , i .Locked )
246253 }
247254
248255 return nil
@@ -310,6 +317,7 @@ func workspaceShow(c TfxClientContext, workspaceName string) error {
310317 }
311318
312319 o .AddDeferredMessageRead ("ID" , w .ID )
320+ o .AddDeferredMessageRead ("Resource Count" , w .ResourceCount )
313321 o .AddDeferredMessageRead ("Terraform Version" , w .TerraformVersion )
314322 o .AddDeferredMessageRead ("Execution Mode" , w .ExecutionMode )
315323 o .AddDeferredMessageRead ("Auto Apply" , w .AutoApply )
0 commit comments