tfjson

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MPL-2.0 Imports: 6 Imported by: 2

README

tfjson

This library is based on hashicorp/terraform-json and provides support for handling JSON outputs for terraform and opentofu.

It includes improvements that are backported from internal libraries and functions, used in Terramate Cloud to handle JSON generated by

Should I use this library?

This library is used in Terramate CLI to improve handling of JSON outputs for Terraform and OpenTofu on the client-side before data is send to Terramate Cloud.

It does not provide any guarantees of compatibility with other applications or future versions.

Please do not depend on this library without contacting us first and share your use case.

What are Terramate CLI and Terramate Cloud?

Terramate CLI is an open-source Infrastructure as Code (IaC) Orchestration and Code Generation tool for Terraform, OpenTofu and Terragrunt. Check terramate.io for more information.

Terramate Cloud is an infrastructure as code management platform.

Documentation

Overview

Package tfjson is a de-coupled helper library containing types for the plan format output by "terraform show -json" command. This command is designed for the export of Terraform plan data in a format that can be easily processed by tools unrelated to Terraform.

This format is stable and should be used over the binary plan data whenever possible.

Index

Constants

This section is empty.

Variables

View Source
var MetadataFunctionsFormatVersionConstraints = "~> 1.0"

MetadataFunctionsFormatVersionConstraints defines the versions of the JSON metadata functions format that are supported by this package.

View Source
var PlanFormatVersionConstraints = ">= 0.1, < 2.0"

PlanFormatVersionConstraints defines the versions of the JSON plan format that are supported by this package.

View Source
var ProviderSchemasFormatVersionConstraints = ">= 0.1, < 2.0"

ProviderSchemasFormatVersionConstraints defines the versions of the JSON provider schema format that are supported by this package.

View Source
var StateFormatVersionConstraints = ">= 0.1, < 2.0"

StateFormatVersionConstraints defines the versions of the JSON state format that are supported by this package.

View Source
var UnknownConstantValue = &unknownConstantValue{}

UnknownConstantValue is a singleton type that denotes that a constant value is explicitly unknown. This is set during an unmarshal when references are found in an expression to help more explicitly differentiate between an explicit null and unknown value.

View Source
var ValidateFormatVersionConstraints = ">= 0.1, < 2.0"

ValidateFormatVersionConstraints defines the versions of the JSON validate format that are supported by this package.

Functions

This section is empty.

Types

type Action

type Action string

Action is a valid action type for a resource change.

Note that a singular Action is not telling of a full resource change operation. Certain resource actions, such as replacement, are a composite of more than one type. See the Actions type and its helpers for more information.

const (
	// ActionNoop denotes a no-op operation.
	ActionNoop Action = "no-op"

	// ActionCreate denotes a create operation.
	ActionCreate Action = "create"

	// ActionRead denotes a read operation.
	ActionRead Action = "read"

	// ActionUpdate denotes an update operation.
	ActionUpdate Action = "update"

	// ActionDelete denotes a delete operation.
	ActionDelete Action = "delete"

	// ActionForget denotes a forget operation.
	ActionForget Action = "forget"
)

type Actions

type Actions []Action

Actions denotes a valid change type.

func (Actions) Create

func (a Actions) Create() bool

Create is true if this set of Actions denotes creation of a new resource.

func (Actions) CreateBeforeDestroy

func (a Actions) CreateBeforeDestroy() bool

CreateBeforeDestroy is true if this set of Actions denotes a create-before-destroy operation, usually the result of replacement to a resource that has the create_before_destroy lifecycle option set.

func (Actions) Delete

func (a Actions) Delete() bool

Delete is true if this set of Actions denotes resource removal.

func (Actions) DestroyBeforeCreate

func (a Actions) DestroyBeforeCreate() bool

DestroyBeforeCreate is true if this set of Actions denotes a destroy-before-create operation. This is the standard resource replacement method.

func (Actions) Forget

func (a Actions) Forget() bool

Forget is true if this set of Actions denotes a forget operation.

func (Actions) NoOp

func (a Actions) NoOp() bool

NoOp is true if this set of Actions denotes a no-op.

func (Actions) Read

func (a Actions) Read() bool

Read is true if this set of Actions denotes a read operation only.

func (Actions) Replace

func (a Actions) Replace() bool

Replace is true if this set of Actions denotes a valid replacement operation.

func (Actions) Update

func (a Actions) Update() bool

Update is true if this set of Actions denotes an update operation.

type Change

type Change struct {
	// The action to be carried out by this change.
	Actions Actions `json:"actions,omitempty"`

	// Before and After are representations of the object value both
	// before and after the action. For create and delete actions,
	// either Before or After is unset (respectively). For no-op
	// actions, both values will be identical. After will be incomplete
	// if there are values within it that won't be known until after
	// apply.
	Before interface{} `json:"before,"`
	After  interface{} `json:"after,omitempty"`

	// A deep object of booleans that denotes any values that are
	// unknown in a resource. These values were previously referred to
	// as "computed" values.
	//
	// If the value cannot be found in this map, then its value should
	// be available within After, so long as the operation supports it.
	AfterUnknown interface{} `json:"after_unknown,omitempty"`

	// BeforeSensitive and AfterSensitive are object values with similar
	// structure to Before and After, but with all sensitive leaf values
	// replaced with true, and all non-sensitive leaf values omitted. These
	// objects should be combined with Before and After to prevent accidental
	// display of sensitive values in user interfaces.
	BeforeSensitive interface{} `json:"before_sensitive,omitempty"`
	AfterSensitive  interface{} `json:"after_sensitive,omitempty"`

	// Importing contains the import metadata about this operation. If importing
	// is present (ie. not null) then the change is an import operation in
	// addition to anything mentioned in the actions field. The actual contents
	// of the Importing struct is subject to change, so downstream consumers
	// should treat any values in here as strictly optional.
	Importing *Importing `json:"importing,omitempty"`

	// GeneratedConfig contains any HCL config generated for this resource
	// during planning as a string.
	//
	// If this is populated, then Importing should also be populated but this
	// might change in the future. However, not all Importing changes will
	// contain generated config.
	GeneratedConfig string `json:"generated_config,omitempty"`

	// ReplacePaths contains a set of paths that point to attributes/elements
	// that are causing the overall resource to be replaced rather than simply
	// updated.
	//
	// This field is always a slice of indexes, where an index in this context
	// is either an integer pointing to a child of a set/list, or a string
	// pointing to the child of a map, object, or block.
	ReplacePaths []interface{} `json:"replace_paths,omitempty"`
}

Change is the representation of a proposed change for an object.

type CheckDynamicAddress

type CheckDynamicAddress struct {
	// ToDisplay is a formatted and ready to display representation of the
	// full address, including the additional information from the relevant
	// CheckStaticAddress.
	ToDisplay string `json:"to_display"`

	// Module is the module part of the address. This address will include the
	// instance key for any module expansions resulting from foreach or count
	// arguments. This field will be empty for any resources within the root
	// module.
	Module string `json:"module,omitempty"`

	// InstanceKey is the instance key for any instances of a given resource.
	//
	// InstanceKey will be empty if there was no foreach or count argument
	// defined on the containing object.
	InstanceKey interface{} `json:"instance_key,omitempty"`
}

CheckDynamicAddress contains the InstanceKey field for any resources that have multiple instances. A complete address can be built by combining the CheckStaticAddress with the CheckDynamicAddress.

type CheckKind

type CheckKind string

CheckKind is a string representation of the type of conditional check referenced in a check result.

const (
	// CheckKindResource indicates the check result is from a pre- or
	// post-condition on a resource or data source.
	CheckKindResource CheckKind = "resource"

	// CheckKindOutputValue indicates the check result is from an output
	// post-condition.
	CheckKindOutputValue CheckKind = "output_value"

	// CheckKindCheckBlock indicates the check result is from a check block.
	CheckKindCheckBlock CheckKind = "check"
)

type CheckResultDynamic

type CheckResultDynamic struct {
	// Address is the relative address of this instance given the Address in the
	// parent object.
	Address CheckDynamicAddress `json:"address"`

	// Status is the overall status for the checks within this dynamic object.
	Status CheckStatus `json:"status"`

	// Problems describes any additional optional details about this check if
	// the check failed.
	//
	// This will not include the errors resulting from this check block, as they
	// will be exposed as diagnostics in the original terraform execution. It
	// may contain any failure messages even if the overall status is
	// CheckStatusError, however, as the instance could contain multiple checks
	// that returned a mix of error and failure statuses.
	Problems []CheckResultProblem `json:"problems,omitempty"`
}

CheckResultDynamic describes the check result for a dynamic object that results from the expansion of the containing object.

type CheckResultProblem

type CheckResultProblem struct {
	// Message is the condition error message provided by the original check
	// author.
	Message string `json:"message"`
}

CheckResultProblem describes one of potentially several problems that led to a check being classied as CheckStatusFail.

type CheckResultStatic

type CheckResultStatic struct {
	// Address is the absolute address of the "checkable object"
	Address CheckStaticAddress `json:"address"`

	// Status is the overall status for all the checks within this object.
	Status CheckStatus `json:"status"`

	// Instances contains the results for dynamic object that belongs to this
	// static object. For example, any instances created from an object using
	// the foreach or count meta arguments.
	//
	// Check blocks and outputs will only contain a single instance, while
	// resources can contain 1 to many.
	Instances []CheckResultDynamic `json:"instances,omitempty"`
}

CheckResultStatic is the container for a "checkable object".

A "checkable object" is a resource or data source, an output, or a check block.

type CheckStaticAddress

type CheckStaticAddress struct {
	// ToDisplay is a formatted and ready to display representation of the
	// address.
	ToDisplay string `json:"to_display"`

	// Kind represents the CheckKind of this check.
	Kind CheckKind `json:"kind"`

	// Module is the module part of the address. This will be empty for any
	// resources in the root module.
	Module string `json:"module,omitempty"`

	// Mode is the ResourceMode of the resource that contains this check. This
	// field is only set is Kind equals CheckKindResource.
	Mode ResourceMode `json:"mode,omitempty"`

	// Type is the resource type for the resource that contains this check. This
	// field is only set if Kind equals CheckKindResource.
	Type string `json:"type,omitempty"`

	// Name is the name of the resource, check block, or output that contains
	// this check.
	Name string `json:"name,omitempty"`
}

CheckStaticAddress details the address of the object that performed a given check. The static address points to the overall resource, as opposed to the dynamic address which contains the instance key for any resource that has multiple instances.

type CheckStatus

type CheckStatus string

CheckStatus is a string representation of the status of a given conditional check.

const (
	// CheckStatusPass indicates the check passed.
	CheckStatusPass CheckStatus = "pass"

	// CheckStatusFail indicates the check failed.
	CheckStatusFail CheckStatus = "fail"

	// CheckStatusError indicates the check errored. This is distinct from
	// CheckStatusFail in that it represents a logical or configuration error
	// within the check block that prevented the check from executing, as
	// opposed to the check was attempted and evaluated to false.
	CheckStatusError CheckStatus = "error"

	// CheckStatusUnknown indicates the result of the check was not known. This
	// could be because a value within the check could not be known at plan
	// time, or because the overall plan failed for an unrelated reason before
	// this check could be executed.
	CheckStatusUnknown CheckStatus = "unknown"
)

type Config

type Config struct {
	// A map of all provider instances across all modules in the
	// configuration.
	//
	// The index for this field is opaque and should not be parsed. Use
	// the individual fields in ProviderConfig to discern actual data
	// about the provider such as name, alias, or defined module.
	ProviderConfigs map[string]*ProviderConfig `json:"provider_config,omitempty"`

	// The root module in the configuration. Any child modules descend
	// off of here.
	RootModule *ConfigModule `json:"root_module,omitempty"`
}

Config represents the complete configuration source.

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(b []byte) error

func (*Config) Validate

func (c *Config) Validate() error

Validate checks to ensure that the config is present.

type ConfigModule

type ConfigModule struct {
	// The outputs defined in the module.
	Outputs map[string]*ConfigOutput `json:"outputs,omitempty"`

	// The resources defined in the module.
	Resources []*ConfigResource `json:"resources,omitempty"`

	// Any "module" stanzas within the specific module.
	ModuleCalls map[string]*ModuleCall `json:"module_calls,omitempty"`

	// The variables defined in the module.
	Variables map[string]*ConfigVariable `json:"variables,omitempty"`
}

ConfigModule describes a module in Terraform configuration.

type ConfigOutput

type ConfigOutput struct {
	// Indicates whether or not the output was marked as sensitive.
	Sensitive bool `json:"sensitive,omitempty"`

	// The defined value of the output.
	Expression *Expression `json:"expression,omitempty"`

	// The defined description of this output.
	Description string `json:"description,omitempty"`

	// The defined dependencies tied to this output.
	DependsOn []string `json:"depends_on,omitempty"`
}

ConfigOutput defines an output as defined in configuration.

type ConfigProvisioner

type ConfigProvisioner struct {
	// The type of the provisioner, ie: "local-exec".
	Type string `json:"type,omitempty"`

	// Any non-special configuration values in the provisioner, indexed by
	// key.
	Expressions map[string]*Expression `json:"expressions,omitempty"`
}

ConfigProvisioner describes a provisioner declared in a resource configuration.

type ConfigResource

type ConfigResource struct {
	// The address of the resource relative to the module that it is
	// in.
	Address string `json:"address,omitempty"`

	// The resource mode.
	Mode ResourceMode `json:"mode,omitempty"`

	// The type of resource, ie: "null_resource" in
	// "null_resource.foo".
	Type string `json:"type,omitempty"`

	// The name of the resource, ie: "foo" in "null_resource.foo".
	Name string `json:"name,omitempty"`

	// An opaque key representing the provider configuration this
	// module uses. Note that there are more than one circumstance that
	// this key will not match what is found in the ProviderConfigs
	// field in the root Config structure, and as such should not be
	// relied on for that purpose.
	ProviderConfigKey string `json:"provider_config_key,omitempty"`

	// The list of provisioner defined for this configuration. This
	// will be nil if no providers are defined.
	Provisioners []*ConfigProvisioner `json:"provisioners,omitempty"`

	// Any non-special configuration values in the resource, indexed by
	// key.
	Expressions map[string]*Expression `json:"expressions,omitempty"`

	// The resource's configuration schema version. With access to the
	// specific Terraform provider for this resource, this can be used
	// to determine the correct schema for the configuration data
	// supplied in Expressions.
	SchemaVersion uint64 `json:"schema_version"`

	// The expression data for the "count" value in the resource.
	CountExpression *Expression `json:"count_expression,omitempty"`

	// The expression data for the "for_each" value in the resource.
	ForEachExpression *Expression `json:"for_each_expression,omitempty"`

	// The contents of the "depends_on" config directive, which
	// declares explicit dependencies for this resource.
	DependsOn []string `json:"depends_on,omitempty"`
}

ConfigResource is the configuration representation of a resource.

type ConfigVariable

type ConfigVariable struct {
	// The defined default value of the variable.
	Default interface{} `json:"default,omitempty"`

	// The defined text description of the variable.
	Description string `json:"description,omitempty"`

	// Whether the variable is marked as sensitive
	Sensitive bool `json:"sensitive,omitempty"`
}

ConfigVariable defines a variable as defined in configuration.

type DeferredResourceChange

type DeferredResourceChange struct {
	// Reason is the reason why this resource change was deferred.
	Reason string `json:"reason,omitempty"`

	// Change contains any information we have about the deferred change.
	ResourceChange *ResourceChange `json:"resource_change,omitempty"`
}

DeferredResourceChange is a description of a resource change that has been deferred for some reason.

type Diagnostic

type Diagnostic struct {
	Severity DiagnosticSeverity `json:"severity,omitempty"`

	Summary string `json:"summary,omitempty"`
	Detail  string `json:"detail,omitempty"`
	Range   *Range `json:"range,omitempty"`

	Snippet *DiagnosticSnippet `json:"snippet,omitempty"`
}

Diagnostic represents information to be presented to a user about an error or anomaly in parsing or evaluating configuration

type DiagnosticExpressionValue

type DiagnosticExpressionValue struct {
	Traversal string `json:"traversal"`
	Statement string `json:"statement"`
}

DiagnosticExpressionValue represents an HCL traversal string (e.g. "var.foo") and a statement about its value while the expression was evaluated (e.g. "is a string", "will be known only after apply"). These are intended to help the consumer diagnose why an expression caused a diagnostic to be emitted.

type DiagnosticSeverity

type DiagnosticSeverity string
const (
	DiagnosticSeverityUnknown DiagnosticSeverity = "unknown"
	DiagnosticSeverityError   DiagnosticSeverity = "error"
	DiagnosticSeverityWarning DiagnosticSeverity = "warning"
)

These severities map to the tfdiags.Severity values, plus an explicit unknown in case that enum grows without us noticing here.

type DiagnosticSnippet

type DiagnosticSnippet struct {
	// Context is derived from HCL's hcled.ContextString output. This gives a
	// high-level summary of the root context of the diagnostic: for example,
	// the resource block in which an expression causes an error.
	Context *string `json:"context"`

	// Code is a possibly-multi-line string of Terraform configuration, which
	// includes both the diagnostic source and any relevant context as defined
	// by the diagnostic.
	Code string `json:"code"`

	// StartLine is the line number in the source file for the first line of
	// the snippet code block. This is not necessarily the same as the value of
	// Range.Start.Line, as it is possible to have zero or more lines of
	// context source code before the diagnostic range starts.
	StartLine int `json:"start_line"`

	// HighlightStartOffset is the character offset into Code at which the
	// diagnostic source range starts, which ought to be highlighted as such by
	// the consumer of this data.
	HighlightStartOffset int `json:"highlight_start_offset"`

	// HighlightEndOffset is the character offset into Code at which the
	// diagnostic source range ends.
	HighlightEndOffset int `json:"highlight_end_offset"`

	// Values is a sorted slice of expression values which may be useful in
	// understanding the source of an error in a complex expression.
	Values []DiagnosticExpressionValue `json:"values"`
}

DiagnosticSnippet represents source code information about the diagnostic. It is possible for a diagnostic to have a source (and therefore a range) but no source code can be found. In this case, the range field will be present and the snippet field will not.

type Expression

type Expression struct {
	*ExpressionData
}

Expression describes the format for an individual key in a Terraform configuration.

This struct wraps ExpressionData to support custom JSON parsing.

func (*Expression) MarshalJSON

func (e *Expression) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Expression.

func (*Expression) UnmarshalJSON

func (e *Expression) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler for Expression.

type ExpressionData

type ExpressionData struct {
	// If the *entire* expression is a constant-defined value, this
	// will contain the Go representation of the expression's data.
	//
	// Note that a nil here denotes and explicit null. When a value is
	// unknown on part of the value coming from an expression that
	// cannot be resolved at parse time, this field will contain
	// UnknownConstantValue.
	ConstantValue interface{} `json:"constant_value,omitempty"`

	// If any part of the expression contained values that were not
	// able to be resolved at parse-time, this will contain a list of
	// the referenced identifiers that caused the value to be unknown.
	References []string `json:"references,omitempty"`

	// A list of complex objects that were nested in this expression.
	// If this value is a nested block in configuration, sometimes
	// referred to as a "sub-resource", this field will contain those
	// values, and ConstantValue and References will be blank.
	NestedBlocks []map[string]*Expression `json:"-"`
}

ExpressionData describes the format for an individual key in a Terraform configuration.

type FunctionParameter

type FunctionParameter struct {
	// Name is an optional name for the argument.
	Name string `json:"name,omitempty"`

	// Description is an optional human-readable description
	// of the argument
	Description string `json:"description,omitempty"`

	// IsNullable is true if null is acceptable value for the argument
	IsNullable bool `json:"is_nullable,omitempty"`

	// A type that any argument for this parameter must conform to.
	Type cty.Type `json:"type"`
}

FunctionParameter represents a parameter to a function.

type FunctionSignature

type FunctionSignature struct {
	// Description is an optional human-readable description
	// of the function
	Description string `json:"description,omitempty"`

	// Summary is an optional shortened description of the function
	Summary string `json:"summary,omitempty"`

	// DeprecationMessage is an optional message that indicates that the
	// function should be considered deprecated and what actions should be
	// performed by the practitioner to handle the deprecation.
	DeprecationMessage string `json:"deprecation_message,omitempty"`

	// ReturnType is the ctyjson representation of the function's
	// return types based on supplying all parameters using
	// dynamic types. Functions can have dynamic return types.
	ReturnType cty.Type `json:"return_type"`

	// Parameters describes the function's fixed positional parameters.
	Parameters []*FunctionParameter `json:"parameters,omitempty"`

	// VariadicParameter describes the function's variadic
	// parameter if it is supported.
	VariadicParameter *FunctionParameter `json:"variadic_parameter,omitempty"`
}

FunctionSignature represents a function signature.

type Importing

type Importing struct {
	// The original ID of this resource used to target it as part of planned
	// import operation.
	ID string `json:"id,omitempty"`
}

Importing is a nested object for the resource import metadata.

type MetadataFunctions

type MetadataFunctions struct {
	// The version of the format. This should always match the
	// MetadataFunctionsFormatVersionConstraints in this package, else
	// unmarshaling will fail.
	FormatVersion string `json:"format_version"`

	// The signatures of the functions available in a Terraform version.
	Signatures map[string]*FunctionSignature `json:"function_signatures,omitempty"`
}

MetadataFunctions is the top-level object returned when exporting function signatures

func (*MetadataFunctions) UnmarshalJSON

func (f *MetadataFunctions) UnmarshalJSON(b []byte) error

func (*MetadataFunctions) Validate

func (f *MetadataFunctions) Validate() error

Validate checks to ensure that MetadataFunctions is present, and the version matches the version supported by this library.

type ModuleCall

type ModuleCall struct {
	// The contents of the "source" field.
	Source string `json:"source,omitempty"`

	// Any non-special configuration values in the module, indexed by
	// key.
	Expressions map[string]*Expression `json:"expressions,omitempty"`

	// The expression data for the "count" value in the module.
	CountExpression *Expression `json:"count_expression,omitempty"`

	// The expression data for the "for_each" value in the module.
	ForEachExpression *Expression `json:"for_each_expression,omitempty"`

	// The configuration data for the module itself.
	Module *ConfigModule `json:"module,omitempty"`

	// The version constraint for modules that come from the registry.
	VersionConstraint string `json:"version_constraint,omitempty"`

	// The explicit resource dependencies for the "depends_on" value.
	// As it must be a slice of references, Expression is not used.
	DependsOn []string `json:"depends_on,omitempty"`
}

ModuleCall describes a declared "module" within a configuration. It also contains the data for the module itself.

type Plan

type Plan struct {

	// The version of the plan format. This should always match the
	// PlanFormatVersion constant in this package, or else an unmarshal
	// will be unstable.
	FormatVersion string `json:"format_version,omitempty"`

	// The version of Terraform used to make the plan.
	TerraformVersion string `json:"terraform_version,omitempty"`

	// The variables set in the root module when creating the plan.
	Variables map[string]*PlanVariable `json:"variables,omitempty"`

	// The common state representation of resources within this plan.
	// This is a product of the existing state merged with the diff for
	// this plan.
	PlannedValues *StateValues `json:"planned_values,omitempty"`

	// The change operations for resources and data sources within this plan
	// resulting from resource drift.
	ResourceDrift []*ResourceChange `json:"resource_drift,omitempty"`

	// The change operations for resources and data sources within this
	// plan.
	ResourceChanges []*ResourceChange `json:"resource_changes,omitempty"`

	// DeferredChanges contains the change operations for resources that are deferred
	// for this plan.
	DeferredChanges []*DeferredResourceChange `json:"deferred_changes,omitempty"`

	// Complete indicates that all resources have successfully planned changes.
	// This will be false if there are DeferredChanges or if the -target flag is used.
	//
	// Complete was introduced in Terraform 1.8 and will be nil for all previous
	// Terraform versions.
	Complete *bool `json:"complete,omitempty"`

	// The change operations for outputs within this plan.
	OutputChanges map[string]*Change `json:"output_changes,omitempty"`

	// The Terraform state prior to the plan operation. This is the
	// same format as PlannedValues, without the current diff merged.
	PriorState *State `json:"prior_state,omitempty"`

	// The Terraform configuration used to make the plan.
	Config *Config `json:"configuration,omitempty"`

	// RelevantAttributes represents any resource instances and their
	// attributes which may have contributed to the planned changes
	RelevantAttributes []ResourceAttribute `json:"relevant_attributes,omitempty"`

	// Checks contains the results of any conditional checks executed, or
	// planned to be executed, during this plan.
	Checks []CheckResultStatic `json:"checks,omitempty"`

	// Timestamp contains the static timestamp that Terraform considers to be
	// the time this plan executed, in UTC.
	Timestamp string `json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

Plan represents the entire contents of an output Terraform plan.

func (*Plan) UnmarshalJSON

func (p *Plan) UnmarshalJSON(b []byte) error

func (*Plan) UseJSONNumber

func (p *Plan) UseJSONNumber(b bool)

UseJSONNumber controls whether the Plan will be decoded using the json.Number behavior or the float64 behavior. When b is true, the Plan will represent numbers in PlanOutputs as json.Numbers. When b is false, the Plan will represent numbers in PlanOutputs as float64s.

func (*Plan) Validate

func (p *Plan) Validate() error

Validate checks to ensure that the plan is present, and the version matches the version supported by this library.

type PlanVariable

type PlanVariable struct {
	// The value for this variable at plan time.
	Value interface{} `json:"value,omitempty"`
}

PlanVariable is a top-level variable in the Terraform plan.

type Pos

type Pos struct {
	Line   int `json:"line"`
	Column int `json:"column"`
	Byte   int `json:"byte"`
}

Pos represents a position in a config file

type ProviderConfig

type ProviderConfig struct {
	// The name of the provider, ie: "aws".
	Name string `json:"name,omitempty"`

	// The fully-specified name of the provider, ie: "registry.terraform.io/hashicorp/aws".
	FullName string `json:"full_name,omitempty"`

	// The alias of the provider, ie: "us-east-1".
	Alias string `json:"alias,omitempty"`

	// The address of the module the provider is declared in.
	ModuleAddress string `json:"module_address,omitempty"`

	// Any non-special configuration values in the provider, indexed by
	// key.
	Expressions map[string]*Expression `json:"expressions,omitempty"`

	// The defined version constraint for this provider.
	VersionConstraint string `json:"version_constraint,omitempty"`
}

ProviderConfig describes a provider configuration instance.

type ProviderSchema

type ProviderSchema struct {
	// The schema for the provider's configuration.
	ConfigSchema *Schema `json:"provider,omitempty"`

	// The schemas for any resources in this provider.
	ResourceSchemas map[string]*Schema `json:"resource_schemas,omitempty"`

	// The schemas for any data sources in this provider.
	DataSourceSchemas map[string]*Schema `json:"data_source_schemas,omitempty"`

	// The definitions for any functions in this provider.
	Functions map[string]*FunctionSignature `json:"functions,omitempty"`
}

ProviderSchema is the JSON representation of the schema of an entire provider, including the provider configuration and any resources and data sources included with the provider.

type ProviderSchemas

type ProviderSchemas struct {
	// The version of the plan format. This should always match one of
	// ProviderSchemasFormatVersions in this package, or else
	// an unmarshal will be unstable.
	FormatVersion string `json:"format_version,omitempty"`

	// The schemas for the providers in this configuration, indexed by
	// provider type. Aliases are not included, and multiple instances
	// of a provider in configuration will be represented by a single
	// provider here.
	Schemas map[string]*ProviderSchema `json:"provider_schemas,omitempty"`
}

ProviderSchemas represents the schemas of all providers and resources in use by the configuration.

func (*ProviderSchemas) UnmarshalJSON

func (p *ProviderSchemas) UnmarshalJSON(b []byte) error

func (*ProviderSchemas) Validate

func (p *ProviderSchemas) Validate() error

Validate checks to ensure that ProviderSchemas is present, and the version matches the version supported by this library.

type Range

type Range struct {
	Filename string `json:"filename"`
	Start    Pos    `json:"start"`
	End      Pos    `json:"end"`
}

Range represents a range of bytes between two positions

type ResourceAttribute

type ResourceAttribute struct {
	// Resource describes resource instance address (e.g. null_resource.foo)
	Resource string `json:"resource"`
	// Attribute describes the attribute path using a lossy representation
	// of cty.Path. (e.g. ["id"] or ["objects", 0, "val"]).
	Attribute []json.RawMessage `json:"attribute"`
}

ResourceAttribute describes a full path to a resource attribute

type ResourceChange

type ResourceChange struct {
	// The absolute resource address.
	Address string `json:"address,omitempty"`

	// The absolute address that this resource instance had
	// at the conclusion of a previous plan.
	PreviousAddress string `json:"previous_address,omitempty"`

	// The module portion of the above address. Omitted if the instance
	// is in the root module.
	ModuleAddress string `json:"module_address,omitempty"`

	// The resource mode.
	Mode ResourceMode `json:"mode,omitempty"`

	// The resource type, example: "aws_instance" for aws_instance.foo.
	Type string `json:"type,omitempty"`

	// The resource name, example: "foo" for aws_instance.foo.
	Name string `json:"name,omitempty"`

	// The instance key for any resources that have been created using
	// "count" or "for_each". If neither of these apply the key will be
	// empty.
	//
	// This value can be either an integer (int) or a string.
	Index interface{} `json:"index,omitempty"`

	// The name of the provider this resource belongs to. This allows
	// the provider to be interpreted unambiguously in the unusual
	// situation where a provider offers a resource type whose name
	// does not start with its own name, such as the "googlebeta"
	// provider offering "google_compute_instance".
	ProviderName string `json:"provider_name,omitempty"`

	// An identifier used during replacement operations, and can be
	// used to identify the exact resource being replaced in state.
	DeposedKey string `json:"deposed,omitempty"`

	// The data describing the change that will be made to this object.
	Change *Change `json:"change,omitempty"`
}

ResourceChange is a description of an individual change action that Terraform plans to use to move from the prior state to a new state matching the configuration.

type ResourceMode

type ResourceMode string

ResourceMode is a string representation of the resource type found in certain fields in the plan.

const (
	// DataResourceMode is the resource mode for data sources.
	DataResourceMode ResourceMode = "data"

	// ManagedResourceMode is the resource mode for managed resources.
	ManagedResourceMode ResourceMode = "managed"
)

type Schema

type Schema struct {
	// The version of the particular resource schema.
	Version uint64 `json:"version"`

	// The root-level block of configuration values.
	Block *SchemaBlock `json:"block,omitempty"`
}

Schema is the JSON representation of a particular schema (provider configuration, resources, data sources).

type SchemaAttribute

type SchemaAttribute struct {
	// The attribute type
	// Either AttributeType or AttributeNestedType is set, never both.
	AttributeType cty.Type `json:"type,omitempty"`

	// Details about a nested attribute type
	// Either AttributeType or AttributeNestedType is set, never both.
	AttributeNestedType *SchemaNestedAttributeType `json:"nested_type,omitempty"`

	// The description field for this attribute. If no kind is
	// provided, it can be assumed to be plain text.
	Description     string                `json:"description,omitempty"`
	DescriptionKind SchemaDescriptionKind `json:"description_kind,omitempty"`

	// If true, this attribute is deprecated.
	Deprecated bool `json:"deprecated,omitempty"`

	// If true, this attribute is required - it has to be entered in
	// configuration.
	Required bool `json:"required,omitempty"`

	// If true, this attribute is optional - it does not need to be
	// entered in configuration.
	Optional bool `json:"optional,omitempty"`

	// If true, this attribute is computed - it can be set by the
	// provider. It may also be set by configuration if Optional is
	// true.
	Computed bool `json:"computed,omitempty"`

	// If true, this attribute is sensitive and will not be displayed
	// in logs. Future versions of Terraform may encrypt or otherwise
	// treat these values with greater care than non-sensitive fields.
	Sensitive bool `json:"sensitive,omitempty"`
}

SchemaAttribute describes an attribute within a schema block.

func (*SchemaAttribute) MarshalJSON

func (as *SchemaAttribute) MarshalJSON() ([]byte, error)

type SchemaBlock

type SchemaBlock struct {
	// The attributes defined at the particular level of this block.
	Attributes map[string]*SchemaAttribute `json:"attributes,omitempty"`

	// Any nested blocks within this particular block.
	NestedBlocks map[string]*SchemaBlockType `json:"block_types,omitempty"`

	// The description for this block and format of the description. If
	// no kind is provided, it can be assumed to be plain text.
	Description     string                `json:"description,omitempty"`
	DescriptionKind SchemaDescriptionKind `json:"description_kind,omitempty"`

	// If true, this block is deprecated.
	Deprecated bool `json:"deprecated,omitempty"`
}

SchemaBlock represents a nested block within a particular schema.

type SchemaBlockType

type SchemaBlockType struct {
	// The nesting mode for this block.
	NestingMode SchemaNestingMode `json:"nesting_mode,omitempty"`

	// The block data for this block type, including attributes and
	// subsequent nested blocks.
	Block *SchemaBlock `json:"block,omitempty"`

	// The lower limit on items that can be declared of this block
	// type.
	MinItems uint64 `json:"min_items,omitempty"`

	// The upper limit on items that can be declared of this block
	// type.
	MaxItems uint64 `json:"max_items,omitempty"`
}

SchemaBlockType describes a nested block within a schema.

type SchemaDescriptionKind

type SchemaDescriptionKind string

SchemaDescriptionKind describes the format type for a particular description's field.

const (
	// SchemaDescriptionKindPlain indicates a string in plain text format.
	SchemaDescriptionKindPlain SchemaDescriptionKind = "plain"

	// SchemaDescriptionKindMarkdown indicates a Markdown string and may need to be
	// processed prior to presentation.
	SchemaDescriptionKindMarkdown SchemaDescriptionKind = "markdown"
)

type SchemaNestedAttributeType

type SchemaNestedAttributeType struct {
	// A map of nested attributes
	Attributes map[string]*SchemaAttribute `json:"attributes,omitempty"`

	// The nesting mode for this attribute.
	NestingMode SchemaNestingMode `json:"nesting_mode,omitempty"`

	// The lower limit on number of items that can be declared
	// of this attribute type (not applicable to single nesting mode).
	MinItems uint64 `json:"min_items,omitempty"`

	// The upper limit on number of items that can be declared
	// of this attribute type (not applicable to single nesting mode).
	MaxItems uint64 `json:"max_items,omitempty"`
}

SchemaNestedAttributeType describes a nested attribute which could also be just expressed simply as cty.Object(...), cty.List(cty.Object(...)) etc. but this allows tracking additional metadata which can help interpreting or validating the data.

type SchemaNestingMode

type SchemaNestingMode string

SchemaNestingMode is the nesting mode for a particular nested schema block.

const (
	// SchemaNestingModeSingle denotes single block nesting mode, which
	// allows a single block of this specific type only in
	// configuration. This is generally the same as list or set types
	// with a single-element constraint.
	SchemaNestingModeSingle SchemaNestingMode = "single"

	// SchemaNestingModeGroup is similar to SchemaNestingModeSingle in that it
	// calls for only a single instance of a given block type with no labels,
	// but it additonally guarantees that its result will never be null,
	// even if the block is absent, and instead the nested attributes
	// and blocks will be treated as absent in that case.
	//
	// This is useful for the situation where a remote API has a feature that
	// is always enabled but has a group of settings related to that feature
	// that themselves have default values. By using SchemaNestingModeGroup
	// instead of SchemaNestingModeSingle in that case, generated plans will
	// show the block as present even when not present in configuration,
	// thus allowing any default values within to be displayed to the user.
	SchemaNestingModeGroup SchemaNestingMode = "group"

	// SchemaNestingModeList denotes list block nesting mode, which
	// allows an ordered list of blocks where duplicates are allowed.
	SchemaNestingModeList SchemaNestingMode = "list"

	// SchemaNestingModeSet denotes set block nesting mode, which
	// allows an unordered list of blocks where duplicates are
	// generally not allowed. What is considered a duplicate is up to
	// the rules of the set itself, which may or may not cover all
	// fields in the block.
	SchemaNestingModeSet SchemaNestingMode = "set"

	// SchemaNestingModeMap denotes map block nesting mode. This
	// creates a map of all declared blocks of the block type within
	// the parent, keying them on the label supplied in the block
	// declaration. This allows for blocks to be declared in the same
	// style as resources.
	SchemaNestingModeMap SchemaNestingMode = "map"
)

type State

type State struct {

	// The version of the state format. This should always match the
	// StateFormatVersion constant in this package, or else am
	// unmarshal will be unstable.
	FormatVersion string `json:"format_version,omitempty"`

	// The Terraform version used to make the state.
	TerraformVersion string `json:"terraform_version,omitempty"`

	// The values that make up the state.
	Values *StateValues `json:"values,omitempty"`

	// Checks contains the results of any conditional checks when Values was
	// last updated.
	Checks []CheckResultStatic `json:"checks,omitempty"`
	// contains filtered or unexported fields
}

State is the top-level representation of a Terraform state.

func (*State) UnmarshalJSON

func (s *State) UnmarshalJSON(b []byte) error

func (*State) UseJSONNumber

func (s *State) UseJSONNumber(b bool)

UseJSONNumber controls whether the State will be decoded using the json.Number behavior or the float64 behavior. When b is true, the State will represent numbers in StateOutputs as json.Numbers. When b is false, the State will represent numbers in StateOutputs as float64s.

func (*State) Validate

func (s *State) Validate() error

Validate checks to ensure that the state is present, and the version matches the version supported by this library.

type StateModule

type StateModule struct {
	// All resources or data sources within this module.
	Resources []*StateResource `json:"resources,omitempty"`

	// The absolute module address, omitted for the root module.
	Address string `json:"address,omitempty"`

	// Any child modules within this module.
	ChildModules []*StateModule `json:"child_modules,omitempty"`
}

StateModule is the representation of a module in the common state representation. This can be the root module or a child module.

type StateOutput

type StateOutput struct {
	// Whether or not the output was marked as sensitive.
	Sensitive bool `json:"sensitive"`

	// The value of the output.
	Value interface{} `json:"value,omitempty"`

	// The type of the output.
	Type cty.Type `json:"type,omitempty"`
}

StateOutput represents an output value in a common state representation.

func (*StateOutput) MarshalJSON

func (so *StateOutput) MarshalJSON() ([]byte, error)

type StateResource

type StateResource struct {
	// The absolute resource address.
	Address string `json:"address,omitempty"`

	// The resource mode.
	Mode ResourceMode `json:"mode,omitempty"`

	// The resource type, example: "aws_instance" for aws_instance.foo.
	Type string `json:"type,omitempty"`

	// The resource name, example: "foo" for aws_instance.foo.
	Name string `json:"name,omitempty"`

	// The instance key for any resources that have been created using
	// "count" or "for_each". If neither of these apply the key will be
	// empty.
	//
	// This value can be either an integer (int) or a string.
	Index interface{} `json:"index,omitempty"`

	// The name of the provider this resource belongs to. This allows
	// the provider to be interpreted unambiguously in the unusual
	// situation where a provider offers a resource type whose name
	// does not start with its own name, such as the "googlebeta"
	// provider offering "google_compute_instance".
	ProviderName string `json:"provider_name,omitempty"`

	// The version of the resource type schema the "values" property
	// conforms to.
	SchemaVersion uint64 `json:"schema_version,"`

	// The JSON representation of the attribute values of the resource,
	// whose structure depends on the resource type schema. Any unknown
	// values are omitted or set to null, making them indistinguishable
	// from absent values.
	AttributeValues map[string]interface{} `json:"values,omitempty"`

	// The JSON representation of the sensitivity of the resource's
	// attribute values. Only attributes which are sensitive
	// are included in this structure.
	SensitiveValues json.RawMessage `json:"sensitive_values,omitempty"`

	// The addresses of the resources that this resource depends on.
	DependsOn []string `json:"depends_on,omitempty"`

	// If true, the resource has been marked as tainted and will be
	// re-created on the next update.
	Tainted bool `json:"tainted,omitempty"`

	// DeposedKey is set if the resource instance has been marked Deposed and
	// will be destroyed on the next apply.
	DeposedKey string `json:"deposed_key,omitempty"`
}

StateResource is the representation of a resource in the common state representation.

type StateValues

type StateValues struct {
	// The Outputs for this common state representation.
	Outputs map[string]*StateOutput `json:"outputs,omitempty"`

	// The root module in this state representation.
	RootModule *StateModule `json:"root_module,omitempty"`
}

StateValues is the common representation of resolved values for both the prior state (which is always complete) and the planned new state.

type ValidateOutput

type ValidateOutput struct {
	FormatVersion string `json:"format_version"`

	Valid        bool         `json:"valid"`
	ErrorCount   int          `json:"error_count"`
	WarningCount int          `json:"warning_count"`
	Diagnostics  []Diagnostic `json:"diagnostics"`
}

ValidateOutput represents JSON output from terraform validate (available from 0.12 onwards)

func (*ValidateOutput) UnmarshalJSON

func (vo *ValidateOutput) UnmarshalJSON(b []byte) error

func (*ValidateOutput) Validate

func (vo *ValidateOutput) Validate() error

Validate checks to ensure that data is present, and the version matches the version supported by this library.

type VersionOutput

type VersionOutput struct {
	Version            string            `json:"terraform_version"`
	Revision           string            `json:"terraform_revision"`
	Platform           string            `json:"platform,omitempty"`
	ProviderSelections map[string]string `json:"provider_selections"`
	Outdated           bool              `json:"terraform_outdated"`
}

VersionOutput represents output from the version -json command added in v0.13

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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