Documentation ¶
Overview ¶
Package jsonplan implements methods for outputting a plan in a machine-readable json format
Index ¶
- Constants
- func Marshal(config *configs.Config, p *plans.Plan, sf *statefile.File, ...) ([]byte, error)
- func MarshalForRenderer(p *plans.Plan, schemas *tofu.Schemas) (map[string]Change, []ResourceChange, []ResourceChange, []ResourceAttr, error)
- func MarshalOutputChanges(changes *plans.Changes) (map[string]Change, error)
- func UnmarshalActions(actions []string) plans.Action
- type AttributeValues
- type Change
- type Importing
- type Module
- type Output
- type Plan
- type Resource
- type ResourceAttr
- type ResourceChange
- type StateValues
- type Variable
- type Variables
Constants ¶
const ( FormatVersion = "1.2" ResourceInstanceReplaceBecauseCannotUpdate = "replace_because_cannot_update" ResourceInstanceReplaceBecauseTainted = "replace_because_tainted" ResourceInstanceReplaceByRequest = "replace_by_request" ResourceInstanceReplaceByTriggers = "replace_by_triggers" ResourceInstanceDeleteBecauseNoResourceConfig = "delete_because_no_resource_config" ResourceInstanceDeleteBecauseWrongRepetition = "delete_because_wrong_repetition" ResourceInstanceDeleteBecauseCountIndex = "delete_because_count_index" ResourceInstanceDeleteBecauseEachKey = "delete_because_each_key" ResourceInstanceDeleteBecauseNoModule = "delete_because_no_module" ResourceInstanceDeleteBecauseNoMoveTarget = "delete_because_no_move_target" ResourceInstanceReadBecauseConfigUnknown = "read_because_config_unknown" ResourceInstanceReadBecauseDependencyPending = "read_because_dependency_pending" ResourceInstanceReadBecauseCheckNested = "read_because_check_nested" )
FormatVersion represents the version of the json format and will be incremented for any change to this format that requires changes to a consuming parser.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
func Marshal( config *configs.Config, p *plans.Plan, sf *statefile.File, schemas *tofu.Schemas, ) ([]byte, error)
Marshal returns the json encoding of a tofu plan.
func MarshalForRenderer ¶
func MarshalForRenderer( p *plans.Plan, schemas *tofu.Schemas, ) (map[string]Change, []ResourceChange, []ResourceChange, []ResourceAttr, error)
MarshalForRenderer returns the pre-json encoding changes of the requested plan, in a format available to the structured renderer.
This function does a small part of the Marshal function, as it only returns the part of the plan required by the jsonformat.Plan renderer.
func MarshalOutputChanges ¶
MarshalOutputChanges converts the provided internal representation of Changes objects into the structured JSON representation.
This function is referenced directly from the structured renderer tests, to ensure parity between the renderers. It probably shouldn't be used anywhere else.
func UnmarshalActions ¶
UnmarshalActions reverses the actionString function.
Types ¶
type AttributeValues ¶
type AttributeValues map[string]interface{}
AttributeValues is the JSON representation of the attribute values of the resource, whose structure depends on the resource type schema.
type Change ¶
type Change struct { // Actions are the actions that will be taken on the object selected by the // properties below. Valid actions values are: // ["no-op"] // ["create"] // ["read"] // ["update"] // ["delete", "create"] // ["create", "delete"] // ["delete"] // The two "replace" actions are represented in this way to allow callers to // e.g. just scan the list for "delete" to recognize all three situations // where the object will be deleted, allowing for any new deletion // combinations that might be added in future. Actions []string `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"], the before and after // values are identical. The "after" value will be incomplete if there are // values within it that won't be known until after apply. Before json.RawMessage `json:"before,omitempty"` After json.RawMessage `json:"after,omitempty"` // AfterUnknown is an object value with similar structure to After, but // with all unknown leaf values replaced with true, and all known leaf // values omitted. This can be combined with After to reconstruct a full // value after the action, including values which will only be known after // apply. AfterUnknown json.RawMessage `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 json.RawMessage `json:"before_sensitive,omitempty"` AfterSensitive json.RawMessage `json:"after_sensitive,omitempty"` // ReplacePaths is an array of arrays representing a set of paths into the // object value which resulted in the action being "replace". This will be // omitted if the action is not replace, or if no paths caused the // replacement (for example, if the resource was tainted). Each path // consists of one or more steps, each of which will be a number or a // string. ReplacePaths json.RawMessage `json:"replace_paths,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, nNot all Importing changes will // contain generated config. GeneratedConfig string `json:"generated_config,omitempty"` }
Change is the representation of a proposed change for an object.
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 Module ¶
type Module struct { // Resources are sorted in a user-friendly order that is undefined at this // time, but consistent. Resources []Resource `json:"resources,omitempty"` // Address is the absolute module address, omitted for the root module Address string `json:"address,omitempty"` // Each module object can optionally have its own nested "child_modules", // recursively describing the full module tree. ChildModules []Module `json:"child_modules,omitempty"` }
Module is the representation of a module in state. This can be the root module or a child module.
type Output ¶
type Output struct { Sensitive bool `json:"sensitive"` Type json.RawMessage `json:"type,omitempty"` Value json.RawMessage `json:"value,omitempty"` }
type Plan ¶
type Plan struct { FormatVersion string `json:"format_version,omitempty"` TerraformVersion string `json:"terraform_version,omitempty"` Variables Variables `json:"variables,omitempty"` PlannedValues StateValues `json:"planned_values,omitempty"` // ResourceDrift and ResourceChanges are sorted in a user-friendly order // that is undefined at this time, but consistent. ResourceDrift []ResourceChange `json:"resource_drift,omitempty"` ResourceChanges []ResourceChange `json:"resource_changes,omitempty"` OutputChanges map[string]Change `json:"output_changes,omitempty"` PriorState json.RawMessage `json:"prior_state,omitempty"` Config json.RawMessage `json:"configuration,omitempty"` RelevantAttributes []ResourceAttr `json:"relevant_attributes,omitempty"` Checks json.RawMessage `json:"checks,omitempty"` Timestamp string `json:"timestamp,omitempty"` Errored bool `json:"errored"` }
Plan is the top-level representation of the json format of a plan. It includes the complete config and current state.
type Resource ¶
type Resource struct { // Address is the absolute resource address Address string `json:"address,omitempty"` // Mode can be "managed" or "data" Mode string `json:"mode,omitempty"` Type string `json:"type,omitempty"` Name string `json:"name,omitempty"` // Index is omitted for a resource not using `count` or `for_each` Index addrs.InstanceKey `json:"index,omitempty"` // ProviderName allows the property "type" 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"` // SchemaVersion indicates which version of the resource type schema the // "values" property conforms to. SchemaVersion uint64 `json:"schema_version"` // AttributeValues is 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 AttributeValues `json:"values,omitempty"` // SensitiveValues is similar to AttributeValues, but with all sensitive // values replaced with true, and all non-sensitive leaf values omitted. SensitiveValues json.RawMessage `json:"sensitive_values,omitempty"` }
Resource is the representation of a resource in the json plan
type ResourceAttr ¶
type ResourceAttr struct { Resource string `json:"resource"` Attr json.RawMessage `json:"attribute"` }
ResourceAttr contains the address and attribute of an external for the RelevantAttributes in the plan.
type ResourceChange ¶
type ResourceChange struct { // Address is the absolute resource address Address string `json:"address,omitempty"` // PreviousAddress is the absolute address that this resource instance had // at the conclusion of a previous run. // // This will typically be omitted, but will be present if the previous // resource instance was subject to a "moved" block that we handled in the // process of creating this plan. // // Note that this behavior diverges from the internal plan data structure, // where the previous address is set equal to the current address in the // common case, rather than being omitted. PreviousAddress string `json:"previous_address,omitempty"` // ModuleAddress is the module portion of the above address. Omitted if the // instance is in the root module. ModuleAddress string `json:"module_address,omitempty"` // "managed" or "data" Mode string `json:"mode,omitempty"` Type string `json:"type,omitempty"` Name string `json:"name,omitempty"` Index json.RawMessage `json:"index,omitempty"` ProviderName string `json:"provider_name,omitempty"` // "deposed", if set, indicates that this action applies to a "deposed" // object of the given instance rather than to its "current" object. Omitted // for changes to the current object. Deposed string `json:"deposed,omitempty"` // Change describes the change that will be made to this object Change Change `json:"change,omitempty"` // ActionReason is a keyword representing some optional extra context // for why the actions in Change.Actions were chosen. // // This extra detail is only for display purposes, to help a UI layer // present some additional explanation to a human user. The possible // values here might grow and change over time, so any consumer of this // information should be resilient to encountering unrecognized values // and treat them as an unspecified reason. ActionReason string `json:"action_reason,omitempty"` }
ResourceChange is a description of an individual change action that OpenTofu plans to use to move from the prior state to a new state matching the configuration.
func MarshalResourceChanges ¶
func MarshalResourceChanges(resources []*plans.ResourceInstanceChangeSrc, schemas *tofu.Schemas) ([]ResourceChange, error)
MarshalResourceChanges converts the provided internal representation of ResourceInstanceChangeSrc objects into the public structured JSON changes.
This function is referenced directly from the structured renderer tests, to ensure parity between the renderers. It probably shouldn't be used anywhere else.
type StateValues ¶
type StateValues struct { Outputs map[string]Output `json:"outputs,omitempty"` RootModule Module `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 Variable ¶
type Variable struct {
Value json.RawMessage `json:"value,omitempty"`
}