terraform

package
v0.0.0-...-1f3526c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: MPL-2.0 Imports: 5 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InputOpts

type InputOpts struct {
	// Id is a unique ID for the question being asked that might be
	// used for logging or to look up a prior answered question.
	Id string

	// Query is a human-friendly question for inputting this value.
	Query string

	// Description is a description about what this option is. Be wary
	// that this will probably be in a terminal so split lines as you see
	// necessary.
	Description string

	// Default will be the value returned if no data is entered.
	Default string

	// Secret should be true if we are asking for sensitive input.
	// If attached to a TTY, Terraform will disable echo.
	Secret bool
}

InputOpts are options for asking for input.

type InputValue

type InputValue struct {
	// Value is the raw value as provided by the user as part of the plan
	// options, or a corresponding similar data structure for non-plan
	// operations.
	//
	// If a particular variable declared in the root module is _not_ set by
	// the user then the caller must still provide an InputValue for it but
	// must set Value to cty.NilVal to represent the absense of a value.
	// This requirement is to help detect situations where the caller isn't
	// correctly detecting and handling all of the declared variables.
	//
	// For historical reasons it's important that callers distinguish the
	// situation of the value not being set at all (cty.NilVal) from the
	// situation of it being explicitly set to null (a cty.NullVal result):
	// for "nullable" input variables that distinction unfortunately decides
	// whether the final value will be the variable's default or will be
	// explicitly null.
	Value cty.Value

	// SourceType is a high-level category for where the value of Value
	// came from, which Terraform Core uses to tailor some of its error
	// messages to be more helpful to the user.
	//
	// Some SourceType values should be accompanied by a populated SourceRange
	// value. See that field's documentation below for more information.
	SourceType ValueSourceType

	// SourceRange provides source location information for values whose
	// SourceType is either ValueFromConfig, ValueFromNamedFile, or
	// ValueForNormalFile. It is not populated for other source types, and so
	// should not be used.
	SourceRange tfdiags.SourceRange
}

InputValue represents a raw value for a root module input variable as provided by the external caller into a function like terraform.Context.Plan.

InputValue should represent as directly as possible what the user set the variable to, without any attempt to convert the value to the variable's type constraint or substitute the configured default values for variables that wasn't set. Those adjustments will be handled by Terraform Core itself as part of performing the requested operation.

A Terraform Core caller must provide an InputValue object for each of the variables declared in the root module, even if the end user didn't provide an explicit value for some of them. See the Value field documentation for how to handle that situation.

Terraform Core also internally uses InputValue to represent the raw value provided for a variable in a child module call, following the same conventions. However, that's an implementation detail not visible to outside callers.

func (*InputValue) GoString

func (v *InputValue) GoString() string

func (*InputValue) HasSourceRange

func (v *InputValue) HasSourceRange() bool

HasSourceRange returns true if the reciever has a source type for which we expect the SourceRange field to be populated with a valid range.

type InputValues

type InputValues map[string]*InputValue

InputValues is a map of InputValue instances.

func InputValuesFromCaller

func InputValuesFromCaller(vals map[string]cty.Value) InputValues

InputValuesFromCaller turns the given map of naked values into an InputValues that attributes each value to "a caller", using the source type ValueFromCaller. This is primarily useful for testing purposes.

This should not be used as a general way to convert map[string]cty.Value into InputValues, since in most real cases we want to set a suitable other SourceType and possibly SourceRange value.

func (InputValues) HasValues

func (vv InputValues) HasValues(vals map[string]cty.Value) bool

HasValues returns true if the reciever has the same values as in the given map, disregarding the source types and source ranges.

Values are compared using the cty "RawEquals" method, which means that unknown values can be considered equal to one another if they are of the same type.

func (InputValues) Identical

func (vv InputValues) Identical(other InputValues) bool

Identical returns true if the given InputValues has the same values, source types, and source ranges as the receiver.

Values are compared using the cty "RawEquals" method, which means that unknown values can be considered equal to one another if they are of the same type.

This method is primarily for testing. For most practical purposes, it's better to use SameValues or HasValues.

func (InputValues) JustValues

func (vv InputValues) JustValues() map[string]cty.Value

JustValues returns a map that just includes the values, discarding the source information.

func (InputValues) Override

func (vv InputValues) Override(others ...InputValues) InputValues

Override merges the given value maps with the receiver, overriding any conflicting keys so that the latest definition wins.

func (InputValues) SameValues

func (vv InputValues) SameValues(other InputValues) bool

SameValues returns true if the given InputValues has the same values as the receiever, disregarding the source types and source ranges.

Values are compared using the cty "RawEquals" method, which means that unknown values can be considered equal to one another if they are of the same type.

type UIInput

type UIInput interface {
	Input(context.Context, *InputOpts) (string, error)
}

UIInput is the interface that must be implemented to ask for input from this user. This should forward the request to wherever the user inputs things to ask for values.

type ValueSourceType

type ValueSourceType rune

ValueSourceType describes what broad category of source location provided a particular value.

const (
	// ValueFromUnknown is the zero value of ValueSourceType and is not valid.
	ValueFromUnknown ValueSourceType = 0

	// ValueFromConfig indicates that a value came from a .tf or .tf.json file,
	// e.g. the default value defined for a variable.
	ValueFromConfig ValueSourceType = 'C'

	// ValueFromAutoFile indicates that a value came from a "values file", like
	// a .tfvars file, that was implicitly loaded by naming convention.
	ValueFromAutoFile ValueSourceType = 'F'

	// ValueFromNamedFile indicates that a value came from a named "values file",
	// like a .tfvars file, that was passed explicitly on the command line (e.g.
	// -var-file=foo.tfvars).
	ValueFromNamedFile ValueSourceType = 'N'

	// ValueFromCLIArg indicates that the value was provided directly in
	// a CLI argument. The name of this argument is not recorded and so it must
	// be inferred from context.
	ValueFromCLIArg ValueSourceType = 'A'

	// ValueFromEnvVar indicates that the value was provided via an environment
	// variable. The name of the variable is not recorded and so it must be
	// inferred from context.
	ValueFromEnvVar ValueSourceType = 'E'

	// ValueFromInput indicates that the value was provided at an interactive
	// input prompt.
	ValueFromInput ValueSourceType = 'I'

	// ValueFromPlan indicates that the value was retrieved from a stored plan.
	ValueFromPlan ValueSourceType = 'P'

	// ValueFromCaller indicates that the value was explicitly overridden by
	// a caller to Context.SetVariable after the context was constructed.
	ValueFromCaller ValueSourceType = 'S'
)

func (ValueSourceType) GoString

func (v ValueSourceType) GoString() string

func (ValueSourceType) HasSourceRange

func (v ValueSourceType) HasSourceRange() bool

HasSourceRange returns true if the reciever is one of the source types that is used along with a valid SourceRange field when appearing inside an InputValue object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL