tfjson

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: MPL-2.0 Imports: 6 Imported by: 281

README

terraform-json

CircleCI GoDoc

This repository houses data types designed to help parse the data produced by two Terraform commands:

While containing mostly data types, there are also a few helpers to assist with working with the data.

This repository also serves as de facto documentation for the formats produced by these commands. For more details, see the GoDoc.

Why a Separate Repository?

To reduce dependencies on any of Terraform core's internals, we've made a design decision to make any helpers or libraries that work with the external JSON data external and not a part of the Terraform GitHub repository itself.

While Terraform core will change often and be relatively unstable, this library will see a smaller amount of change. Most of the major changes have already happened leading up to 0.12, so you can expect this library to only see minor incremental changes going forward.

For this reason, terraform show -json and terraform providers schema -json is the recommended format for working with Terraform data externally, and as such, if you require any help working with the data in these formats, or even a reference of how the JSON is formatted, use this repository.

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 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"
)

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) 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"`
}

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

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 added in v0.4.0

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 Diagnostic added in v0.7.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 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.
	ResourceChanges []*ResourceChange `json:"resource_changes,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"`
}

Plan represents the entire contents of an output Terraform plan.

func (*Plan) UnmarshalJSON added in v0.4.0

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

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 added in v0.7.0

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"`
}

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 added in v0.4.0

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 added in v0.7.0

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 added in v0.14.0

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 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 added in v0.13.0

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 added in v0.5.0

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 added in v0.9.0

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"`
	// contains filtered or unexported fields
}

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

func (*State) UnmarshalJSON added in v0.4.0

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

func (*State) UseJSONNumber added in v0.8.0

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 added in v0.14.0

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 added in v0.7.0

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 added in v0.9.0

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

func (*ValidateOutput) Validate added in v0.9.0

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 added in v0.7.0

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