github.com/jd3nn1s/terraform@v0.9.6-0.20170906225847-13878347b7a1/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 args, err := c.Meta.process(args, true) 19 if err != nil { 20 return 1 21 } 22 23 envCommandShowWarning(c.Ui, c.LegacyName) 24 25 cmdFlags := c.Meta.flagSet("workspace") 26 cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } 27 28 c.Ui.Output(c.Help()) 29 return 0 30 } 31 32 func (c *WorkspaceCommand) Help() string { 33 helpText := ` 34 Usage: terraform workspace 35 36 Create, change and delete Terraform workspaces. 37 38 39 Subcommands: 40 41 show Show the current workspace name. 42 list List workspaces. 43 select Select a workspace. 44 new Create a new workspace. 45 delete Delete an existing workspace. 46 ` 47 return strings.TrimSpace(helpText) 48 } 49 50 func (c *WorkspaceCommand) Synopsis() string { 51 return "Workspace management" 52 } 53 54 // validWorkspaceName returns true is this name is valid to use as a workspace name. 55 // Since most named states are accessed via a filesystem path or URL, check if 56 // escaping the name would be required. 57 func validWorkspaceName(name string) bool { 58 return name == url.PathEscape(name) 59 } 60 61 func envCommandShowWarning(ui cli.Ui, show bool) { 62 if !show { 63 return 64 } 65 66 ui.Warn(`Warning: the "terraform env" family of commands is deprecated. 67 68 "Workspace" is now the preferred term for what earlier Terraform versions 69 called "environment", to reduce ambiguity caused by the latter term colliding 70 with other concepts. 71 72 The "terraform workspace" commands should be used instead. "terraform env" 73 will be removed in a future Terraform version. 74 `) 75 } 76 77 const ( 78 envNotSupported = `Backend does not support multiple workspaces` 79 80 envExists = `Workspace %q already exists` 81 82 envDoesNotExist = ` 83 Workspace %q doesn't exist. 84 85 You can create this workspace with the "new" subcommand.` 86 87 envChanged = `[reset][green]Switched to workspace %q.` 88 89 envCreated = ` 90 [reset][green][bold]Created and switched to workspace %q![reset][green] 91 92 You're now on a new, empty workspace. Workspaces isolate their state, 93 so if you run "terraform plan" Terraform will not see any existing state 94 for this configuration. 95 ` 96 97 envDeleted = `[reset][green]Deleted workspace %q!` 98 99 envNotEmpty = ` 100 Workspace %[1]q is not empty. 101 102 Deleting %[1]q can result in dangling resources: resources that 103 exist but are no longer manageable by Terraform. Please destroy 104 these resources first. If you want to delete this workspace 105 anyway and risk dangling resources, use the '-force' flag. 106 ` 107 108 envWarnNotEmpty = `[reset][yellow]WARNING: %q was non-empty. 109 The resources managed by the deleted workspace may still exist, 110 but are no longer manageable by Terraform since the state has 111 been deleted. 112 ` 113 114 envDelCurrent = ` 115 Workspace %[1]q is your active workspace. 116 117 You cannot delete the currently active workspace. Please switch 118 to another workspace and try again. 119 ` 120 121 envInvalidName = ` 122 The workspace name %q is not allowed. The name must contain only URL safe 123 characters, and no path separators. 124 ` 125 126 envIsOverriddenNote = ` 127 128 The active workspace is being overridden using the TF_WORKSPACE environment 129 variable. 130 ` 131 132 envIsOverriddenSelectError = ` 133 The selected workspace is currently overridden using the TF_WORKSPACE 134 environment variable. 135 136 To select a new workspace, either update this environment variable or unset 137 it and then run this command again. 138 ` 139 140 envIsOverriddenNewError = ` 141 The workspace is currently overridden using the TF_WORKSPACE environment 142 variable. You cannot create a new workspace when using this setting. 143 144 To create a new workspace, either unset this environment variable or update it 145 to match the workspace name you are trying to create, and then run this command 146 again. 147 ` 148 )