Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/admin_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func getAllMetrics() (*MetricsAll, error) {

func getAllOrganizationWorkspaces(ctx context.Context, client *tfe.Client, orgName string) (*MetricsWorkspaces, error) {
result := &MetricsWorkspaces{}
workspaces, err := workspaceListAllForOrganization(getTfxClientContext(), orgName, "")
workspaces, err := workspaceListAllForOrganization(getTfxClientContext(), orgName, "", "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func getAllMetricsWorkspace(orgName string, since time.Time) (*MetricsWorkspaceR

func getOrganizationMetricWorkspaces(ctx context.Context, client *tfe.Client, orgName string, runSinceTime time.Time) (*[]MetricsWorkspace, error) {
result := []MetricsWorkspace{}
workspaces, err := workspaceListAllForOrganization(getTfxClientContext(), orgName, "")
workspaces, err := workspaceListAllForOrganization(getTfxClientContext(), orgName, "", "")
if err != nil {
return nil, err
}
Expand Down
32 changes: 20 additions & 12 deletions cmd/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ var (
getTfxClientContext(),
*viperString("search"),
*viperString("repository"),
*viperString("run-status"))
*viperString("run-status"),
*viperString("project-id"),
)
} else {
return workspaceList(
getTfxClientContext(),
*viperString("search"),
*viperString("repository"),
*viperString("run-status"))
*viperString("run-status"),
*viperString("project-id"),
)
}
},
}
Expand All @@ -83,6 +87,8 @@ func init() {
workspaceListCmd.Flags().StringP("search", "s", "", "Search string for Workspace Name (optional).")
workspaceListCmd.Flags().StringP("repository", "r", "", "Filter on Repository Identifier (i.e. username/repo_name) (optional).")
workspaceListCmd.Flags().String("run-status", "", "Filter on current run status (optional).")
workspaceListCmd.Flags().String("project-id", "", "Filter on project ID (optional).")

workspaceListCmd.Flags().BoolP("all", "a", false, "List All Organizations Workspaces (optional).")

// `tfx workspace show`
Expand All @@ -94,14 +100,15 @@ func init() {
workspaceCmd.AddCommand(workspaceShowCmd)
}

func workspaceListAllForOrganization(c TfxClientContext, orgName string, searchString string) ([]*tfe.Workspace, error) {
func workspaceListAllForOrganization(c TfxClientContext, orgName string, searchString string, projectID string) ([]*tfe.Workspace, error) {
allItems := []*tfe.Workspace{}
opts := tfe.WorkspaceListOptions{
ListOptions: tfe.ListOptions{PageNumber: 1, PageSize: 100},
Search: searchString,
// Tags: "",
// ExcludeTags: "",
Include: []tfe.WSIncludeOpt{"organization", "current_run"},
ProjectID: projectID,
Include: []tfe.WSIncludeOpt{"organization", "current_run"},
}
for {
items, err := c.Client.Workspaces.List(c.Context, orgName, &opts)
Expand Down Expand Up @@ -163,9 +170,9 @@ func workspaceListAllRemoteStateConsumers(c TfxClientContext, workspaceId string
return allItems, nil
}

func workspaceList(c TfxClientContext, searchString string, repoIdentifier string, runStatus string) error {
func workspaceList(c TfxClientContext, searchString string, repoIdentifier string, runStatus string, projectID string) error {
o.AddMessageUserProvided("List Workspaces for Organization:", c.OrganizationName)
items, err := workspaceListAllForOrganization(c, c.OrganizationName, searchString)
items, err := workspaceListAllForOrganization(c, c.OrganizationName, searchString, projectID)
if err != nil {
return errors.Wrap(err, "failed to list workspaces")
}
Expand All @@ -180,7 +187,7 @@ func workspaceList(c TfxClientContext, searchString string, repoIdentifier strin
o.AddFormattedMessageCalculated("Found %d Filtered Workspaces", len(items))
}

o.AddTableHeader("Name", "Id", "Current Run Created", "Status", "Repository", "Locked")
o.AddTableHeader("Name", "Id", "Resource Count", "Current Run Created", "Status", "Repository", "Locked")
for _, i := range items {
cr_created_at := ""
cr_status := ""
Expand All @@ -193,13 +200,13 @@ func workspaceList(c TfxClientContext, searchString string, repoIdentifier strin
ws_repo = i.VCSRepo.DisplayIdentifier
}

o.AddTableRows(i.Name, i.ID, cr_created_at, cr_status, ws_repo, i.Locked)
o.AddTableRows(i.Name, i.ID, i.ResourceCount, cr_created_at, cr_status, ws_repo, i.Locked)
}

return nil
}

func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier string, runStatus string) error {
func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier string, runStatus string, projectID string) error {
o.AddMessageUserProvided("List Workspaces for all available Organizations", "")
orgs, err := organizationListAll(c)
if err != nil {
Expand All @@ -208,7 +215,7 @@ func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier st

var allWorkspaceList []*tfe.Workspace
for _, v := range orgs {
workspaceList, err := workspaceListAllForOrganization(c, v.Name, searchString)
workspaceList, err := workspaceListAllForOrganization(c, v.Name, searchString, projectID)
if err != nil {
logError(err, "failed to list workspaces for organization")
}
Expand All @@ -229,7 +236,7 @@ func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier st
o.AddFormattedMessageCalculated("Found %d Filtered Workspaces", len(allWorkspaceList))
}

o.AddTableHeader("Organization", "Name", "Id", "Current Run Created", "Status", "Repository", "Locked")
o.AddTableHeader("Organization", "Name", "Id", "Resource Count", "Current Run Created", "Status", "Repository", "Locked")
for _, i := range allWorkspaceList {
cr_created_at := ""
cr_status := ""
Expand All @@ -242,7 +249,7 @@ func workspaceListAll(c TfxClientContext, searchString string, repoIdentifier st
ws_repo = i.VCSRepo.DisplayIdentifier
}

o.AddTableRows(i.Organization.Name, i.Name, i.ID, cr_created_at, cr_status, ws_repo, i.Locked)
o.AddTableRows(i.Organization.Name, i.Name, i.ID, i.ResourceCount, cr_created_at, cr_status, ws_repo, i.Locked)
}

return nil
Expand Down Expand Up @@ -310,6 +317,7 @@ func workspaceShow(c TfxClientContext, workspaceName string) error {
}

o.AddDeferredMessageRead("ID", w.ID)
o.AddDeferredMessageRead("Resource Count", w.ResourceCount)
o.AddDeferredMessageRead("Terraform Version", w.TerraformVersion)
o.AddDeferredMessageRead("Execution Mode", w.ExecutionMode)
o.AddDeferredMessageRead("Auto Apply", w.AutoApply)
Expand Down
10 changes: 6 additions & 4 deletions cmd/workspace_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ var (
RunE: func(cmd *cobra.Command, args []string) error {
return workspaceLockAll(
getTfxClientContext(),
*viperString("search"))
*viperString("search"),
)
},
}

Expand All @@ -71,7 +72,8 @@ var (
RunE: func(cmd *cobra.Command, args []string) error {
return workspaceUnlockAll(
getTfxClientContext(),
*viperString("search"))
*viperString("search"),
)
},
}
)
Expand Down Expand Up @@ -111,7 +113,7 @@ func workspaceLock(c TfxClientContext, workspaceName string) error {

func workspaceLockAll(c TfxClientContext, searchString string) error {
o.AddMessageUserProvided("Lock All Workspace in Organization:", c.OrganizationName)
workspaceList, err := workspaceListAllForOrganization(c, c.OrganizationName, searchString)
workspaceList, err := workspaceListAllForOrganization(c, c.OrganizationName, searchString, "")
if err != nil {
return errors.Wrap(err, "failed to list workspaces")
}
Expand Down Expand Up @@ -145,7 +147,7 @@ func workspaceUnlock(c TfxClientContext, workspaceName string) error {

func workspaceUnlockAll(c TfxClientContext, searchString string) error {
o.AddMessageUserProvided("Unlock All Workspace in Organization:", c.OrganizationName)
workspaceList, err := workspaceListAllForOrganization(c, c.OrganizationName, searchString)
workspaceList, err := workspaceListAllForOrganization(c, c.OrganizationName, searchString, "")
if err != nil {
return errors.Wrap(err, "failed to list workspaces")
}
Expand Down
Loading