tfops

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HCLMAINFILE = "main.tf.json"
	HCLLOCKFILE = ".terraform.hcl.lock"
	TFSTATEFILE = "terraform.tfstate"
)

Variables

This section is empty.

Functions

func ConvertTFState

func ConvertTFState(tfState *TFState, providerAddr string) models.Resource

ConvertTFState convert Terraform State to kusion State

func GetWorkSpaceDir

func GetWorkSpaceDir() (string, error)

GetWrokSpaceDir return kusion terrafrom runtime workspace dir Defalut workspace dir is ~/.kusion/.terraform

func TFError

func TFError(infos []byte) error

TFError parse Terraform CLI output infos return error with given infos

Types

type Diagnostic

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

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

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 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 TFState

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

Terraform State schema from https://github.com/hashicorp/terraform/blob/main/internal/command/jsonstate/state.go

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(resource *models.Resource, fs afero.Afero) *WorkSpace

func (*WorkSpace) Apply

func (w *WorkSpace) Apply(ctx context.Context) (*TFState, error)

Apply invoke terraform apply cli

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 erros 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) Read

func (w *WorkSpace) Read(ctx context.Context) (*TFState, error)

Read make terraform show call. Return terraform state model TODO: terraform show livestate.

func (*WorkSpace) RefreshOnly

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

Refresh Sync Terraform State

func (*WorkSpace) SetResource

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

SetResource set workspace resource

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 *models.Resource) error

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

type WorkspaceStore

type WorkspaceStore struct {
	Store map[string]*WorkSpace
	Fs    afero.Afero
}

WorkspaceStore store Terraform workspaces.

func GetWorkspaceStore

func GetWorkspaceStore(fs afero.Afero) (WorkspaceStore, error)

GetWorkspaceStore find directory in the filesystem and store workspace return all terraform workspace record in the filesystem.

func (*WorkspaceStore) Create

func (ws *WorkspaceStore) Create(ctx context.Context, resource *models.Resource) error

Create make Terraform workspace for given resources. convert kusion resource to hcl json and write to file and init in the workspace folder

func (*WorkspaceStore) Remove

func (ws *WorkspaceStore) Remove(ctx context.Context, resource *models.Resource) error

Remove delete workspace directory and delete its record from the store.

Jump to

Keyboard shortcuts

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