Files

103 lines
3.1 KiB
Go
Raw Permalink Normal View History

// Copyright (c) HashiCorp, Inc.
2023-08-10 15:53:29 -07:00
// SPDX-License-Identifier: BUSL-1.1
2020-05-08 16:41:47 +02:00
package packer
import (
hcl "github.com/hashicorp/hcl/v2"
2020-12-17 13:29:25 -08:00
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
plugingetter "github.com/hashicorp/packer/packer/plugin-getter"
)
2020-05-08 16:41:47 +02:00
type GetBuildsOptions struct {
// Get builds except the ones that match with except and with only the ones
2020-05-08 16:59:19 +02:00
// that match with Only. When those are empty everything matches.
2020-05-08 16:41:47 +02:00
Except, Only []string
Debug, Force bool
OnError string
// count only/except match count; so say something when nothing matched.
ExceptMatches, OnlyMatches int
2020-05-08 16:41:47 +02:00
}
type BuildGetter interface {
2020-05-12 12:29:31 +02:00
// GetBuilds return all possible builds for a config. It also starts all
// builders.
2020-05-08 16:41:47 +02:00
// TODO(azr): rename to builder starter ?
2024-03-01 11:21:02 -05:00
GetBuilds(GetBuildsOptions) ([]*CoreBuild, hcl.Diagnostics)
2020-05-08 16:41:47 +02:00
}
2020-06-05 17:23:54 +02:00
type Evaluator interface {
// EvaluateExpression is meant to be used in the `packer console` command.
// It parses the input string and returns what needs to be displayed. In
// case of an error the error should be displayed.
EvaluateExpression(expr string) (output string, exit bool, diags hcl.Diagnostics)
}
2021-01-20 10:37:16 +01:00
type InitializeOptions struct {
// When set, the execution of datasources will be skipped and the datasource will provide
// an output spec that will be used for validation only.
2021-01-20 10:37:16 +01:00
SkipDatasourcesExecution bool
// UseSequential changes the way data sources and locals are evaluated.
//
// In this mode, instead of using two separate phases to evaluate datasources first, then
// local variables, here we instead use a DAG so both are evaluated at once, based on the
// dependencies between them.
//
// This is optional and defaults to false for now, but this may become a default later.
UseSequential bool
2021-01-20 10:37:16 +01:00
}
2023-07-11 15:41:37 -04:00
type PluginBinaryDetector interface {
// DetectPluginBinaries is used only for HCL2 templates, and loads required
// plugins if specified.
DetectPluginBinaries() hcl.Diagnostics
}
// The Handler handles all Packer things. This interface reflects the Packer
// commands, ex: init, console ( evaluate ), fix config, inspect config, etc. To
// run a build we will start the builds and then the core of Packer handles
// execution.
2020-06-05 17:23:54 +02:00
type Handler interface {
2021-01-20 10:37:16 +01:00
Initialize(InitializeOptions) hcl.Diagnostics
// PluginRequirements returns the list of plugin Requirements from the
// config file.
PluginRequirements() (plugingetter.Requirements, hcl.Diagnostics)
2020-06-05 17:23:54 +02:00
Evaluator
BuildGetter
ConfigFixer
2020-06-23 11:58:57 +02:00
ConfigInspector
2023-07-11 15:41:37 -04:00
PluginBinaryDetector
2020-06-05 17:23:54 +02:00
}
2020-05-08 16:54:44 +02:00
//go:generate enumer -type FixConfigMode
2020-05-08 16:41:47 +02:00
type FixConfigMode int
const (
2020-05-12 13:03:43 +02:00
// Stdout will make FixConfig simply print what the config should be; it
// will only work when a single file is passed.
2020-05-08 16:54:44 +02:00
Stdout FixConfigMode = iota
2020-05-12 12:29:31 +02:00
// Inplace fixes your files on the spot.
2020-05-08 16:54:44 +02:00
Inplace
2020-05-12 12:29:31 +02:00
// Diff shows a full diff.
2020-05-08 16:54:44 +02:00
Diff
2020-05-08 16:41:47 +02:00
)
type FixConfigOptions struct {
Mode FixConfigMode
2020-05-08 16:41:47 +02:00
}
2020-05-12 12:29:31 +02:00
type ConfigFixer interface {
2020-05-08 16:41:47 +02:00
// FixConfig will output the config in a fixed manner.
FixConfig(FixConfigOptions) hcl.Diagnostics
}
2020-06-23 11:58:57 +02:00
type InspectConfigOptions struct {
packersdk.Ui
2020-06-23 11:58:57 +02:00
}
type ConfigInspector interface {
// Inspect will output self inspection for a configuration
InspectConfig(InspectConfigOptions) (ret int)
}