github.com/hashicorp/packer@v1.14.3/packer/run_interfaces.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package packer 5 6 import ( 7 hcl "github.com/hashicorp/hcl/v2" 8 packersdk "github.com/hashicorp/packer-plugin-sdk/packer" 9 plugingetter "github.com/hashicorp/packer/packer/plugin-getter" 10 ) 11 12 type GetBuildsOptions struct { 13 // Get builds except the ones that match with except and with only the ones 14 // that match with Only. When those are empty everything matches. 15 Except, Only []string 16 Debug, Force bool 17 OnError string 18 19 // count only/except match count; so say something when nothing matched. 20 ExceptMatches, OnlyMatches int 21 } 22 23 type BuildGetter interface { 24 // GetBuilds return all possible builds for a config. It also starts all 25 // builders. 26 // TODO(azr): rename to builder starter ? 27 GetBuilds(GetBuildsOptions) ([]*CoreBuild, hcl.Diagnostics) 28 } 29 30 type Evaluator interface { 31 // EvaluateExpression is meant to be used in the `packer console` command. 32 // It parses the input string and returns what needs to be displayed. In 33 // case of an error the error should be displayed. 34 EvaluateExpression(expr string) (output string, exit bool, diags hcl.Diagnostics) 35 } 36 37 type InitializeOptions struct { 38 // When set, the execution of datasources will be skipped and the datasource will provide 39 // an output spec that will be used for validation only. 40 SkipDatasourcesExecution bool 41 // UseSequential changes the way data sources and locals are evaluated. 42 // 43 // In this mode, instead of using two separate phases to evaluate datasources first, then 44 // local variables, here we instead use a DAG so both are evaluated at once, based on the 45 // dependencies between them. 46 // 47 // This is optional and defaults to false for now, but this may become a default later. 48 UseSequential bool 49 } 50 51 type PluginBinaryDetector interface { 52 // DetectPluginBinaries is used only for HCL2 templates, and loads required 53 // plugins if specified. 54 DetectPluginBinaries() hcl.Diagnostics 55 } 56 57 // The Handler handles all Packer things. This interface reflects the Packer 58 // commands, ex: init, console ( evaluate ), fix config, inspect config, etc. To 59 // run a build we will start the builds and then the core of Packer handles 60 // execution. 61 type Handler interface { 62 Initialize(InitializeOptions) hcl.Diagnostics 63 // PluginRequirements returns the list of plugin Requirements from the 64 // config file. 65 PluginRequirements() (plugingetter.Requirements, hcl.Diagnostics) 66 Evaluator 67 BuildGetter 68 ConfigFixer 69 ConfigInspector 70 PluginBinaryDetector 71 } 72 73 //go:generate enumer -type FixConfigMode 74 type FixConfigMode int 75 76 const ( 77 // Stdout will make FixConfig simply print what the config should be; it 78 // will only work when a single file is passed. 79 Stdout FixConfigMode = iota 80 // Inplace fixes your files on the spot. 81 Inplace 82 // Diff shows a full diff. 83 Diff 84 ) 85 86 type FixConfigOptions struct { 87 Mode FixConfigMode 88 } 89 90 type ConfigFixer interface { 91 // FixConfig will output the config in a fixed manner. 92 FixConfig(FixConfigOptions) hcl.Diagnostics 93 } 94 95 type InspectConfigOptions struct { 96 packersdk.Ui 97 } 98 99 type ConfigInspector interface { 100 // Inspect will output self inspection for a configuration 101 InspectConfig(InspectConfigOptions) (ret int) 102 }