github.com/hugorut/terraform@v1.1.3/src/backend/cli.go (about) 1 package backend 2 3 import ( 4 "github.com/mitchellh/cli" 5 "github.com/mitchellh/colorstring" 6 7 "github.com/hugorut/terraform/src/terminal" 8 "github.com/hugorut/terraform/src/terraform" 9 ) 10 11 // CLI is an optional interface that can be implemented to be initialized 12 // with information from the Terraform CLI. If this is implemented, this 13 // initialization function will be called with data to help interact better 14 // with a CLI. 15 // 16 // This interface was created to improve backend interaction with the 17 // official Terraform CLI while making it optional for API users to have 18 // to provide full CLI interaction to every backend. 19 // 20 // If you're implementing a Backend, it is acceptable to require CLI 21 // initialization. In this case, your backend should be coded to error 22 // on other methods (such as State, Operation) if CLI initialization was not 23 // done with all required fields. 24 type CLI interface { 25 Backend 26 27 // CLIInit is called once with options. The options passed to this 28 // function may not be modified after calling this since they can be 29 // read/written at any time by the Backend implementation. 30 // 31 // This may be called before or after Configure is called, so if settings 32 // here affect configurable settings, care should be taken to handle 33 // whether they should be overwritten or not. 34 CLIInit(*CLIOpts) error 35 } 36 37 // CLIOpts are the options passed into CLIInit for the CLI interface. 38 // 39 // These options represent the functionality the CLI exposes and often 40 // maps to meta-flags available on every CLI (such as -input). 41 // 42 // When implementing a backend, it isn't expected that every option applies. 43 // Your backend should be documented clearly to explain to end users what 44 // options have an affect and what won't. In some cases, it may even make sense 45 // to error in your backend when an option is set so that users don't make 46 // a critically incorrect assumption about behavior. 47 type CLIOpts struct { 48 // CLI and Colorize control the CLI output. If CLI is nil then no CLI 49 // output will be done. If CLIColor is nil then no coloring will be done. 50 CLI cli.Ui 51 CLIColor *colorstring.Colorize 52 53 // Streams describes the low-level streams for Stdout, Stderr and Stdin, 54 // including some metadata about whether they are terminals. Most output 55 // should go via the object in field CLI above, but Streams can be useful 56 // for tailoring the output to fit the attached terminal, for example. 57 Streams *terminal.Streams 58 59 // StatePath is the local path where state is read from. 60 // 61 // StateOutPath is the local path where the state will be written. 62 // If this is empty, it will default to StatePath. 63 // 64 // StateBackupPath is the local path where a backup file will be written. 65 // If this is empty, no backup will be taken. 66 StatePath string 67 StateOutPath string 68 StateBackupPath string 69 70 // ContextOpts are the base context options to set when initializing a 71 // Terraform context. Many of these will be overridden or merged by 72 // Operation. See Operation for more details. 73 ContextOpts *terraform.ContextOpts 74 75 // Input will ask for necessary input prior to performing any operations. 76 // 77 // Validation will perform validation prior to running an operation. The 78 // variable naming doesn't match the style of others since we have a func 79 // Validate. 80 Input bool 81 Validation bool 82 83 // RunningInAutomation indicates that commands are being run by an 84 // automated system rather than directly at a command prompt. 85 // 86 // This is a hint not to produce messages that expect that a user can 87 // run a follow-up command, perhaps because Terraform is running in 88 // some sort of workflow automation tool that abstracts away the 89 // exact commands that are being run. 90 RunningInAutomation bool 91 }