github.com/nevins-b/terraform@v0.3.8-0.20170215184714-bbae22007d5a/backend/cli.go (about) 1 package backend 2 3 import ( 4 "github.com/hashicorp/terraform/terraform" 5 "github.com/mitchellh/cli" 6 "github.com/mitchellh/colorstring" 7 ) 8 9 // CLI is an optional interface that can be implemented to be initialized 10 // with information from the Terraform CLI. If this is implemented, this 11 // initialization function will be called with data to help interact better 12 // with a CLI. 13 // 14 // This interface was created to improve backend interaction with the 15 // official Terraform CLI while making it optional for API users to have 16 // to provide full CLI interaction to every backend. 17 // 18 // If you're implementing a Backend, it is acceptable to require CLI 19 // initialization. In this case, your backend should be coded to error 20 // on other methods (such as State, Operation) if CLI initialization was not 21 // done with all required fields. 22 type CLI interface { 23 Backend 24 25 // CLIIinit is called once with options. The options passed to this 26 // function may not be modified after calling this since they can be 27 // read/written at any time by the Backend implementation. 28 CLIIinit(*CLIOpts) error 29 } 30 31 // CLIOpts are the options passed into CLIInit for the CLI interface. 32 // 33 // These options represent the functionality the CLI exposes and often 34 // maps to meta-flags available on every CLI (such as -input). 35 // 36 // When implementing a backend, it isn't expected that every option applies. 37 // Your backend should be documented clearly to explain to end users what 38 // options have an affect and what won't. In some cases, it may even make sense 39 // to error in your backend when an option is set so that users don't make 40 // a critically incorrect assumption about behavior. 41 type CLIOpts struct { 42 // CLI and Colorize control the CLI output. If CLI is nil then no CLI 43 // output will be done. If CLIColor is nil then no coloring will be done. 44 CLI cli.Ui 45 CLIColor *colorstring.Colorize 46 47 // StatePath is the local path where state is read from. 48 // 49 // StateOutPath is the local path where the state will be written. 50 // If this is empty, it will default to StatePath. 51 // 52 // StateBackupPath is the local path where a backup file will be written. 53 // If this is empty, no backup will be taken. 54 StatePath string 55 StateOutPath string 56 StateBackupPath string 57 58 // ContextOpts are the base context options to set when initializing a 59 // Terraform context. Many of these will be overridden or merged by 60 // Operation. See Operation for more details. 61 ContextOpts *terraform.ContextOpts 62 63 // Input will ask for necessary input prior to performing any operations. 64 // 65 // Validation will perform validation prior to running an operation. The 66 // variable naming doesn't match the style of others since we have a func 67 // Validate. 68 Input bool 69 Validation bool 70 }