tfops

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockHCLFile = ".terraform.lock.hcl"
)

Variables

This section is empty.

Functions

func ConvertTFState

func ConvertTFState(tfState *StateRepresentation, providerAddr string) v1.Resource

ConvertTFState convert Terraform DeprecatedState to kusion DeprecatedState

func TFError

func TFError(infos []byte) error

TFError parse Terraform CLI output infos return error with given infos

Types

type Change added in v0.8.0

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

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

type Diagnostic

type Diagnostic struct {
	Severity string   `json:"severity"`
	Summary  string   `json:"summary"`
	Detail   string   `json:"detail"`
	Range    *Range   `json:"range,omitempty"`
	Snippet  *Snippet `json:"snippet,omitempty"`
}

Diagnostic represents relevant fields of a Terraform CLI JSON-formatted log line diagnostic info

type InstanceKey added in v0.7.3

type InstanceKey interface {
	String() string

	// Value returns the cty.Value of the appropriate type for the InstanceKey
	// value.
	Value() cty.Value
	// contains filtered or unexported methods
}

InstanceKey represents the key of an instance within an object that contains multiple instances due to using "count" or "for_each" arguments in configuration.

IntKey and StringKey are the two implementations of this type. No other implementations are allowed. The single instance of an object that _isn't_ using "count" or "for_each" is represented by NoKey, which is a nil InstanceKey.

type PlanRepresentation added in v0.8.0

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

PlanRepresentation is the top-level representation of the json format of a plan. It includes the complete config and current state. Ref: https://developer.hashicorp.com/terraform/internals/json-format#plan-representation

type Pos

type Pos struct {
	// Line is a one-based count for the line in the indicated file.
	Line int `json:"line"`

	// Column is a one-based count of Unicode characters from the start of the line.
	Column int `json:"column"`

	// Byte is a zero-based offset into the indicated file.
	Byte int `json:"byte"`
}

Pos represents a position in the source code.

type Range

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

DiagnosticRange represents the filename and position of the diagnostic subject. This defines the range of the source to be highlighted in the output. Note that the snippet may include additional surrounding source code if the diagnostic has a context range.

The Start position is inclusive, and the End position is exclusive. Exact positions are intended for highlighting for human interpretation only and are subject to change.

type ResourceAttr added in v0.8.0

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

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 Terraform plans to use to move from the prior state to a new state matching the configuration.

type Snippet

type Snippet struct {
	Context              string        `json:"context"`
	Code                 string        `json:"code"`
	StartLine            int           `json:"start_line"`
	HighlightStartOffset int           `json:"highlight_start_offset"`
	HighlightEndOffset   int           `json:"highlight_end_offset"`
	Values               []interface{} `json:"values"`
}

Snippet 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 StateRepresentation added in v0.8.0

type StateRepresentation struct {
	FormatVersion    string       `json:"format_version,omitempty"`
	TerraformVersion string       `json:"terraform_version,omitempty"`
	Values           *stateValues `json:"values,omitempty"`
}

StateRepresentation is the top-level representation of the json format of a terraform StateRepresentation schema from https://github.com/hashicorp/terraform/blob/main/internal/command/jsonstate/state.go https://developer.hashicorp.com/terraform/internals/json-format#state-representation

type TerraformInfo

type TerraformInfo struct {
	Level      string     `json:"@level"`
	Message    string     `json:"@message"`
	Module     string     `json:"@module"`
	Timestamp  time.Time  `json:"@timestamp"`
	Diagnostic Diagnostic `json:"diagnostic"`
	Type       string     `json:"type"`
}

TerraformInfo represent fields of a Terraform CLI JSON-formatted log line

type WorkSpace

type WorkSpace struct {
	// contains filtered or unexported fields
}

func NewWorkSpace

func NewWorkSpace(fs afero.Afero) *WorkSpace

func (*WorkSpace) Apply

Apply with the terraform cli apply command

func (*WorkSpace) CleanAndInitWorkspace added in v0.7.3

func (w *WorkSpace) CleanAndInitWorkspace(ctx context.Context) error

CleanAndInitWorkspace will clean up the provider cache and reinitialize the workspace when the provider version or hash is updated.

func (*WorkSpace) Destroy

func (w *WorkSpace) Destroy(ctx context.Context) error

Destroy make terraform destroy call.

func (*WorkSpace) GetProvider

func (w *WorkSpace) GetProvider() (string, error)

GetProvider get provider addr from terraform lock file. return provider addr and errors eg. registry.terraform.io/hashicorp/local/2.2.3

func (*WorkSpace) InitWorkSpace

func (w *WorkSpace) InitWorkSpace(ctx context.Context) error

InitWorkSpace init terraform runtime workspace

func (*WorkSpace) Plan added in v0.8.0

Plan with the terraform cli plan command

func (*WorkSpace) RefreshOnly

func (w *WorkSpace) RefreshOnly(ctx context.Context) (*StateRepresentation, error)

RefreshOnly refresh Terraform DeprecatedState

func (*WorkSpace) SetCacheDir added in v0.7.4

func (w *WorkSpace) SetCacheDir(cacheDir string)

SetCacheDir set tf cache work directory.

func (*WorkSpace) SetFS added in v0.7.4

func (w *WorkSpace) SetFS(fs afero.Afero)

SetFS set filesystem

func (*WorkSpace) SetResource

func (w *WorkSpace) SetResource(resource *v1.Resource)

SetResource set workspace resource

func (*WorkSpace) SetStackDir added in v0.7.4

func (w *WorkSpace) SetStackDir(stackDir string)

SetStackDir set workspace work directory.

func (*WorkSpace) ShowPlan added in v0.8.0

func (w *WorkSpace) ShowPlan(ctx context.Context) (*PlanRepresentation, error)

ShowPlan shows local plan file with the terraform cli show command

func (*WorkSpace) ShowState added in v0.8.0

func (w *WorkSpace) ShowState(ctx context.Context) (*StateRepresentation, error)

ShowState shows local tfstate with the terraform cli show command

func (*WorkSpace) WriteHCL

func (w *WorkSpace) WriteHCL() error

WriteHCL convert kusion Resource to HCL json and write hcl json to main.tf.json

func (*WorkSpace) WriteTFState

func (w *WorkSpace) WriteTFState(priorState *v1.Resource) error

WriteTFState writes StateRepresentation to the file, this function is for terraform apply refresh only

Jump to

Keyboard shortcuts

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