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