github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/workspace_command.go (about) 1 package command 2 3 import ( 4 "net/url" 5 "strings" 6 7 "github.com/mitchellh/cli" 8 ) 9 10 // WorkspaceCommand is a Command Implementation that manipulates workspaces, 11 // which allow multiple distinct states and variables from a single config. 12 type WorkspaceCommand struct { 13 Meta 14 LegacyName bool 15 } 16 17 func (c *WorkspaceCommand) Run(args []string) int { 18 c.Meta.process(args) 19 envCommandShowWarning(c.Ui, c.LegacyName) 20 21 cmdFlags := c.Meta.extendedFlagSet("workspace") 22 cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } 23 24 return cli.RunResultHelp 25 } 26 27 func (c *WorkspaceCommand) Help() string { 28 helpText := ` 29 Usage: terraform [global options] workspace 30 31 new, list, show, select and delete Terraform workspaces. 32 33 ` 34 return strings.TrimSpace(helpText) 35 } 36 37 func (c *WorkspaceCommand) Synopsis() string { 38 return "Workspace management" 39 } 40 41 // validWorkspaceName returns true is this name is valid to use as a workspace name. 42 // Since most named states are accessed via a filesystem path or URL, check if 43 // escaping the name would be required. 44 func validWorkspaceName(name string) bool { 45 return name == url.PathEscape(name) 46 } 47 48 func envCommandShowWarning(ui cli.Ui, show bool) { 49 if !show { 50 return 51 } 52 53 ui.Warn(`Warning: the "terraform env" family of commands is deprecated. 54 55 "Workspace" is now the preferred term for what earlier Terraform versions 56 called "environment", to reduce ambiguity caused by the latter term colliding 57 with other concepts. 58 59 The "terraform workspace" commands should be used instead. "terraform env" 60 will be removed in a future Terraform version. 61 `) 62 } 63 64 const ( 65 envExists = `Workspace %q already exists` 66 67 envDoesNotExist = ` 68 Workspace %q doesn't exist. 69 70 You can create this workspace with the "new" subcommand 71 or include the "-or-create" flag with the "select" subcommand.` 72 73 envChanged = `[reset][green]Switched to workspace %q.` 74 75 envCreated = ` 76 [reset][green][bold]Created and switched to workspace %q![reset][green] 77 78 You're now on a new, empty workspace. Workspaces isolate their state, 79 so if you run "terraform plan" Terraform will not see any existing state 80 for this configuration. 81 ` 82 83 envDeleted = `[reset][green]Deleted workspace %q!` 84 85 envWarnNotEmpty = `[reset][yellow]WARNING: %q was non-empty. 86 The resources managed by the deleted workspace may still exist, 87 but are no longer manageable by Terraform since the state has 88 been deleted. 89 ` 90 91 envDelCurrent = ` 92 Workspace %[1]q is your active workspace. 93 94 You cannot delete the currently active workspace. Please switch 95 to another workspace and try again. 96 ` 97 98 envInvalidName = ` 99 The workspace name %q is not allowed. The name must contain only URL safe 100 characters, and no path separators. 101 ` 102 103 envIsOverriddenNote = ` 104 105 The active workspace is being overridden using the TF_WORKSPACE environment 106 variable. 107 ` 108 109 envIsOverriddenSelectError = ` 110 The selected workspace is currently overridden using the TF_WORKSPACE 111 environment variable. 112 113 To select a new workspace, either update this environment variable or unset 114 it and then run this command again. 115 ` 116 117 envIsOverriddenNewError = ` 118 The workspace is currently overridden using the TF_WORKSPACE environment 119 variable. You cannot create a new workspace when using this setting. 120 121 To create a new workspace, either unset this environment variable or update it 122 to match the workspace name you are trying to create, and then run this command 123 again. 124 ` 125 )