github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/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 // CLIInit 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 // 29 // This may be called before or after Configure is called, so if settings 30 // here affect configurable settings, care should be taken to handle 31 // whether they should be overwritten or not. 32 CLIInit(*CLIOpts) error 33 } 34 35 // CLIOpts are the options passed into CLIInit for the CLI interface. 36 // 37 // These options represent the functionality the CLI exposes and often 38 // maps to meta-flags available on every CLI (such as -input). 39 // 40 // When implementing a backend, it isn't expected that every option applies. 41 // Your backend should be documented clearly to explain to end users what 42 // options have an affect and what won't. In some cases, it may even make sense 43 // to error in your backend when an option is set so that users don't make 44 // a critically incorrect assumption about behavior. 45 type CLIOpts struct { 46 // CLI and Colorize control the CLI output. If CLI is nil then no CLI 47 // output will be done. If CLIColor is nil then no coloring will be done. 48 CLI cli.Ui 49 CLIColor *colorstring.Colorize 50 51 // ShowDiagnostics is a function that will format and print diagnostic 52 // messages to the UI. 53 ShowDiagnostics func(vals ...interface{}) 54 55 // StatePath is the local path where state is read from. 56 // 57 // StateOutPath is the local path where the state will be written. 58 // If this is empty, it will default to StatePath. 59 // 60 // StateBackupPath is the local path where a backup file will be written. 61 // If this is empty, no backup will be taken. 62 StatePath string 63 StateOutPath string 64 StateBackupPath string 65 66 // ContextOpts are the base context options to set when initializing a 67 // Terraform context. Many of these will be overridden or merged by 68 // Operation. See Operation for more details. 69 ContextOpts *terraform.ContextOpts 70 71 // Input will ask for necessary input prior to performing any operations. 72 // 73 // Validation will perform validation prior to running an operation. The 74 // variable naming doesn't match the style of others since we have a func 75 // Validate. 76 Input bool 77 Validation bool 78 79 // RunningInAutomation indicates that commands are being run by an 80 // automated system rather than directly at a command prompt. 81 // 82 // This is a hint not to produce messages that expect that a user can 83 // run a follow-up command, perhaps because Terraform is running in 84 // some sort of workflow automation tool that abstracts away the 85 // exact commands that are being run. 86 RunningInAutomation bool 87 }