github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/command/env_command.go (about) 1 package command 2 3 import ( 4 "net/url" 5 "strings" 6 ) 7 8 // EnvCommand is a Command Implementation that manipulates local state 9 // environments. 10 type EnvCommand struct { 11 Meta 12 } 13 14 func (c *EnvCommand) Run(args []string) int { 15 args = c.Meta.process(args, true) 16 17 cmdFlags := c.Meta.flagSet("env") 18 cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } 19 20 c.Ui.Output(c.Help()) 21 return 0 22 } 23 24 func (c *EnvCommand) Help() string { 25 helpText := ` 26 Usage: terraform env 27 28 Create, change and delete Terraform environments. 29 30 31 Subcommands: 32 33 list List environments. 34 select Select an environment. 35 new Create a new environment. 36 delete Delete an existing environment. 37 ` 38 return strings.TrimSpace(helpText) 39 } 40 41 func (c *EnvCommand) Synopsis() string { 42 return "Environment management" 43 } 44 45 // validEnvName returns true is this name is valid to use as an environment name. 46 // Since most named states are accessed via a filesystem path or URL, check if 47 // escaping the name would be required. 48 func validEnvName(name string) bool { 49 return name == url.PathEscape(name) 50 } 51 52 const ( 53 envNotSupported = `Backend does not support environments` 54 55 envExists = `Environment %q already exists` 56 57 envDoesNotExist = ` 58 Environment %q doesn't exist! 59 60 You can create this environment with the "new" option.` 61 62 envChanged = `[reset][green]Switched to environment %q!` 63 64 envCreated = ` 65 [reset][green][bold]Created and switched to environment %q![reset][green] 66 67 You're now on a new, empty environment. Environments isolate their state, 68 so if you run "terraform plan" Terraform will not see any existing state 69 for this configuration. 70 ` 71 72 envDeleted = `[reset][green]Deleted environment %q!` 73 74 envNotEmpty = ` 75 Environment %[1]q is not empty! 76 77 Deleting %[1]q can result in dangling resources: resources that 78 exist but are no longer manageable by Terraform. Please destroy 79 these resources first. If you want to delete this environment 80 anyways and risk dangling resources, use the '-force' flag. 81 ` 82 83 envWarnNotEmpty = `[reset][yellow]WARNING: %q was non-empty. 84 The resources managed by the deleted environment may still exist, 85 but are no longer manageable by Terraform since the state has 86 been deleted. 87 ` 88 89 envDelCurrent = ` 90 Environment %[1]q is your active environment! 91 92 You cannot delete the currently active environment. Please switch 93 to another environment and try again. 94 ` 95 96 envInvalidName = ` 97 The environment name %q is not allowed. The name must contain only URL safe 98 characters, and no path separators. 99 ` 100 )