Help us shape the future of Go! Take the 2026 Go Developer Survey

pkg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AbsDir func(string) (string, error) = filepath.Abs
View Source
var ToHclFunc = function.New(&function.Spec{
	Description: "Convert an cty.Value to HCL config in string format",
	Params: []function.Parameter{
		{
			Name: "input",
			Type: cty.DynamicPseudoType,
		},
	},
	Type: function.StaticReturnType(cty.String),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		input := args[0]
		return cty.StringVal(string(hclwrite.TokensForValue(input).BuildTokens(nil).Bytes())), nil
	},
})

Functions

func LoadMPTFHclBlocks

func LoadMPTFHclBlocks(ignoreUnsupportedBlock bool, dir string) ([]*golden.HclBlock, error)

Types

type AppendBlockBodyTransform

type AppendBlockBodyTransform struct {
	*golden.BaseBlock
	*BaseTransform
	TargetBlockAddress string `hcl:"target_block_address" validate:"required"`
	BlockBody          string `hcl:"block_body" validate:"required"`
}

func (*AppendBlockBodyTransform) Apply

func (u *AppendBlockBodyTransform) Apply() error

func (*AppendBlockBodyTransform) PatchWriteBlock

func (u *AppendBlockBodyTransform) PatchWriteBlock(dest terraform.Block, patch *hclwrite.Body)

func (*AppendBlockBodyTransform) String

func (u *AppendBlockBodyTransform) String() string

func (*AppendBlockBodyTransform) Type

func (u *AppendBlockBodyTransform) Type() string

type BaseData

type BaseData struct{}

func (*BaseData) AddressLength

func (rd *BaseData) AddressLength() int

func (*BaseData) BlockType

func (bd *BaseData) BlockType() string

func (*BaseData) CanExecutePrePlan

func (bd *BaseData) CanExecutePrePlan() bool

func (*BaseData) Data

func (bd *BaseData) Data()

type BaseTransform

type BaseTransform struct{}

func (*BaseTransform) AddressLength

func (bt *BaseTransform) AddressLength() int

func (*BaseTransform) BlockType

func (bt *BaseTransform) BlockType() string

func (*BaseTransform) CanExecutePrePlan

func (bt *BaseTransform) CanExecutePrePlan() bool

func (*BaseTransform) Transform

func (bt *BaseTransform) Transform()

type Data

type Data interface {
	golden.PlanBlock
	Data()
}

type DataLocal

type DataLocal struct {
	*BaseData
	*golden.BaseBlock

	ExpectedNameName string    `hcl:"name,optional"`
	Result           cty.Value `attribute:"result"`
}

func (*DataLocal) ExecuteDuringPlan

func (dl *DataLocal) ExecuteDuringPlan() error

func (*DataLocal) String

func (dl *DataLocal) String() string

func (*DataLocal) Type

func (dl *DataLocal) Type() string

type DataModule

type DataModule struct {
	*BaseData
	*golden.BaseBlock

	ExpectedModuleName string    `hcl:"name,optional"`
	Result             cty.Value `attribute:"result"`
}

DataModule exposes every `module` block in the target Terraform module as a map keyed by module name. Each value is the block's full EvalContext — stringified attributes plus an `mptf` metadata sub-object.

Optional `name` filter narrows the result to a single module block.

func (*DataModule) ExecuteDuringPlan

func (d *DataModule) ExecuteDuringPlan() error

func (*DataModule) String

func (d *DataModule) String() string

func (*DataModule) Type

func (d *DataModule) Type() string

type DataMoved

type DataMoved struct {
	*BaseData
	*golden.BaseBlock

	Result cty.Value `attribute:"result"`
}

DataMoved exposes every `moved` block in the target Terraform module as a map keyed by a synthetic, declaration-order index ("0", "1", ...). Moved blocks have no native label, so the index is the only stable way to address them individually.

Each value is the block's EvalContext — `from` and `to` attribute strings plus an `mptf` metadata sub-object.

func (*DataMoved) ExecuteDuringPlan

func (d *DataMoved) ExecuteDuringPlan() error

func (*DataMoved) String

func (d *DataMoved) String() string

func (*DataMoved) Type

func (d *DataMoved) Type() string

type DataOutput

type DataOutput struct {
	*BaseData
	*golden.BaseBlock

	ExpectedOutputName string    `attribute:"name"`
	Result             cty.Value `attribute:"result"`
}

func (*DataOutput) ExecuteDuringPlan

func (d *DataOutput) ExecuteDuringPlan() error

func (*DataOutput) String

func (d *DataOutput) String() string

func (*DataOutput) Type

func (d *DataOutput) Type() string

type DataSourceData

type DataSourceData struct {
	*BaseData
	*golden.BaseBlock

	DataSourceType string    `hcl:"data_source_type,optional"`
	UseCount       bool      `hcl:"use_count,optional" default:"false"`
	UseForEach     bool      `hcl:"use_for_each,optional" default:"false"`
	Result         cty.Value `attribute:"result"`
}

func (*DataSourceData) ExecuteDuringPlan

func (dd *DataSourceData) ExecuteDuringPlan() error

func (*DataSourceData) String

func (dd *DataSourceData) String() string

func (*DataSourceData) Type

func (dd *DataSourceData) Type() string

type DataVariable

type DataVariable struct {
	*BaseData
	*golden.BaseBlock

	ExpectedNameName string    `hcl:"name,optional"`
	ExpectedType     string    `hcl:"type,optional"`
	Result           cty.Value `attribute:"result"`
}

func (*DataVariable) ExecuteDuringPlan

func (dd *DataVariable) ExecuteDuringPlan() error

func (*DataVariable) String

func (dd *DataVariable) String() string

func (*DataVariable) Type

func (dd *DataVariable) Type() string

type EnsureLocalTransform

type EnsureLocalTransform struct {
	*golden.BaseBlock
	*BaseTransform
	LocalName        string `hcl:"name" validate:"required"`
	FallbackFileName string `hcl:"fallback_file_name" validate:"required"`
	// contains filtered or unexported fields
}

func (*EnsureLocalTransform) Apply

func (u *EnsureLocalTransform) Apply() error

func (*EnsureLocalTransform) Decode

func (u *EnsureLocalTransform) Decode(block *golden.HclBlock, context *hcl.EvalContext) error

func (*EnsureLocalTransform) String

func (u *EnsureLocalTransform) String() string

func (*EnsureLocalTransform) Type

func (u *EnsureLocalTransform) Type() string

type MetaProgrammingTFConfig

type MetaProgrammingTFConfig struct {
	*golden.BaseConfig
	// contains filtered or unexported fields
}

func NewMetaProgrammingTFConfig

func NewMetaProgrammingTFConfig(m *TerraformModuleRef, varConfigDir *string, hclBlocks []*golden.HclBlock, cliFlagAssignedVars []golden.CliFlagAssignedVariables, ctx context.Context) (*MetaProgrammingTFConfig, error)

func (*MetaProgrammingTFConfig) AddBlock

func (c *MetaProgrammingTFConfig) AddBlock(filename string, block *hclwrite.Block)

func (*MetaProgrammingTFConfig) DataBlocks

func (c *MetaProgrammingTFConfig) DataBlocks() []*terraform.RootBlock

func (*MetaProgrammingTFConfig) Init

func (c *MetaProgrammingTFConfig) Init(hclBlocks []*golden.HclBlock) error

func (*MetaProgrammingTFConfig) LocalBlocks

func (c *MetaProgrammingTFConfig) LocalBlocks() []*terraform.RootBlock

func (*MetaProgrammingTFConfig) ModuleBlocks

func (c *MetaProgrammingTFConfig) ModuleBlocks() []*terraform.RootBlock

func (*MetaProgrammingTFConfig) MovedBlocks

func (c *MetaProgrammingTFConfig) MovedBlocks() []*terraform.RootBlock

func (*MetaProgrammingTFConfig) OutputBlocks

func (c *MetaProgrammingTFConfig) OutputBlocks() []*terraform.RootBlock

func (*MetaProgrammingTFConfig) ResourceBlocks

func (c *MetaProgrammingTFConfig) ResourceBlocks() []*terraform.RootBlock

func (*MetaProgrammingTFConfig) RootBlock

func (c *MetaProgrammingTFConfig) RootBlock(address string) *terraform.RootBlock

func (*MetaProgrammingTFConfig) SaveToDisk

func (c *MetaProgrammingTFConfig) SaveToDisk() error

func (*MetaProgrammingTFConfig) TerraformBlock

func (c *MetaProgrammingTFConfig) TerraformBlock() *terraform.RootBlock

func (*MetaProgrammingTFConfig) VariableBlocks

func (c *MetaProgrammingTFConfig) VariableBlocks() []*terraform.RootBlock

type MetaProgrammingTFPlan

type MetaProgrammingTFPlan struct {
	Transforms []Transform
	// contains filtered or unexported fields
}

func (*MetaProgrammingTFPlan) Apply

func (m *MetaProgrammingTFPlan) Apply() error

func (*MetaProgrammingTFPlan) String

func (m *MetaProgrammingTFPlan) String() string

type MoveBlockTransform

type MoveBlockTransform struct {
	*golden.BaseBlock
	*BaseTransform
	TargetBlockAddress string `hcl:"target_block_address"`
	FileName           string `hcl:"file_name" validate:"endswith=.tf"`
}

func (*MoveBlockTransform) Apply

func (m *MoveBlockTransform) Apply() error

func (*MoveBlockTransform) Type

func (m *MoveBlockTransform) Type() string

type NewBlockTransform

type NewBlockTransform struct {
	*golden.BaseBlock
	*BaseTransform
	NewBlockType string   `hcl:"new_block_type"`
	FileName     string   `hcl:"filename" validate:"endswith=.tf"`
	Labels       []string `hcl:"labels,optional"`
	NewBody      string   `hcl:"body,optional"`
	// contains filtered or unexported fields
}

func (*NewBlockTransform) Apply

func (n *NewBlockTransform) Apply() error

func (*NewBlockTransform) Decode

func (n *NewBlockTransform) Decode(block *golden.HclBlock, context *hcl.EvalContext) error

func (*NewBlockTransform) Format

func (n *NewBlockTransform) Format(block *hclwrite.Block) (*hclwrite.Block, error)

func (*NewBlockTransform) NewWriteBlock

func (n *NewBlockTransform) NewWriteBlock() *hclwrite.Block

func (*NewBlockTransform) Type

func (n *NewBlockTransform) Type() string

type ProviderSchemaData

type ProviderSchemaData struct {
	*BaseData
	*golden.BaseBlock

	Source    string    `hcl:"provider_source"`
	Version   string    `hcl:"provider_version"`
	Resources cty.Value `attribute:"resources"`
}

func (*ProviderSchemaData) Convert

func (r *ProviderSchemaData) Convert(schemas map[string]*tfjson.Schema) (cty.Value, error)

func (*ProviderSchemaData) ExecuteDuringPlan

func (r *ProviderSchemaData) ExecuteDuringPlan() error

func (*ProviderSchemaData) Type

func (r *ProviderSchemaData) Type() string

type RegexReplaceExpressionTransform

type RegexReplaceExpressionTransform struct {
	*golden.BaseBlock
	*BaseTransform
	Regex       string `hcl:"regex" validate:"required"`
	Replacement string `hcl:"replacement"`
}

func (*RegexReplaceExpressionTransform) Apply

func (*RegexReplaceExpressionTransform) Type

type RemoveBlockContentBlockTransform

type RemoveBlockContentBlockTransform struct {
	*golden.BaseBlock
	*BaseTransform
	TargetBlockAddress string   `hcl:"target_block_address"`
	Paths              []string `hcl:"paths"`
}

func (*RemoveBlockContentBlockTransform) Apply

func (*RemoveBlockContentBlockTransform) Type

type RemoveBlockTransform

type RemoveBlockTransform struct {
	*golden.BaseBlock
	*BaseTransform
	TargetBlockAddress string `hcl:"target_block_address"`
}

func (*RemoveBlockTransform) Apply

func (r *RemoveBlockTransform) Apply() error

func (*RemoveBlockTransform) Type

func (r *RemoveBlockTransform) Type() string

type Rename

type Rename struct {
	ResourceType string `hcl:"resource_type"`
	// We'll deprecate `attribute_path` in favor of `element_path`.
	AttributePath           []string `hcl:"attribute_path,optional" validate:"excluded_with=element_path"`
	ElementPath             []string `hcl:"element_path,optional" validate:"excluded_with=attribute_path,required_without=attribute_path"`
	NewName                 string   `hcl:"new_name" validate:"required"`
	RenameOnlyNewNameAbsent bool     `hcl:"rename_only_new_name_absent,optional" default:"false"`
}

type RenameAttributeOrNestedBlockTransform

type RenameAttributeOrNestedBlockTransform struct {
	*golden.BaseBlock
	*BaseTransform
	Renames []Rename `hcl:"rename,block"`
}

func (*RenameAttributeOrNestedBlockTransform) Apply

func (*RenameAttributeOrNestedBlockTransform) Type

type ReorderAttributesTransform

type ReorderAttributesTransform struct {
	*golden.BaseBlock
	*BaseTransform
	TargetBlockAddress       string   `hcl:"target_block_address"`
	HeadAttributes           []string `hcl:"head_attributes,optional"`
	TailAttributes           []string `hcl:"tail_attributes,optional"`
	HeadTailLineBreaks       *bool    `hcl:"head_tail_line_breaks,optional"`
	SortMiddleAlphabetically *bool    `hcl:"sort_middle_alphabetically,optional"`
}

ReorderAttributesTransform re-orders the attributes and nested blocks of one root block.

Semantics:

  • "Element" = an attribute (name = value) or a nested block. Nested blocks are identified by their type name, except for `dynamic "X"` blocks which are identified by their label (`X`), so they line up with the static block they emit.
  • Elements named in `head_attributes` come first, in the listed order.
  • Elements named in `tail_attributes` come last, in the listed order.
  • Every other element is the "middle". By default the middle is sorted alphabetically by name; set `sort_middle_alphabetically = false` to preserve the original source order instead.
  • When `head_tail_line_breaks` is true (default) a blank line is inserted between the head section and the middle, and between the middle and the tail section. Set to `false` to suppress these blank lines.
  • Every nested block in the output is preceded by a blank line — if a blank line is already there (because of the head/tail rule above) no extra blank line is inserted.
  • Names in `head_attributes` / `tail_attributes` that are not present on the block are silently skipped.
  • The same name in both `head_attributes` and `tail_attributes` is a configuration error.

This transform never adds, removes, or mutates attribute values — only the layout changes.

func (*ReorderAttributesTransform) Apply

func (r *ReorderAttributesTransform) Apply() error

func (*ReorderAttributesTransform) Type

type RequiredProvider

type RequiredProvider struct {
	Source  *string `attribute:"source"`
	Version *string `attribute:"version"`
}

type ResourceData

type ResourceData struct {
	*BaseData
	*golden.BaseBlock

	ResourceType string    `hcl:"resource_type,optional"`
	UseCount     bool      `hcl:"use_count,optional" default:"false"`
	UseForEach   bool      `hcl:"use_for_each,optional" default:"false"`
	Result       cty.Value `attribute:"result"`
}

func (*ResourceData) ExecuteDuringPlan

func (rd *ResourceData) ExecuteDuringPlan() error

func (*ResourceData) String

func (rd *ResourceData) String() string

func (*ResourceData) Type

func (rd *ResourceData) Type() string

type SortBlocksInFileTransform

type SortBlocksInFileTransform struct {
	*golden.BaseBlock
	*BaseTransform
	FileName     string   `hcl:"file_name" validate:"endswith=.tf"`
	DesiredOrder []string `hcl:"desired_order" validate:"required,min=1,unique,dive,min=1"`
}

SortBlocksInFileTransform ensures every block listed in `desired_order` lives in `file_name`, in the listed order, after any blocks that are already in the file but absent from the list.

Semantics:

  • For each address in `desired_order`, the block is removed from whichever file currently holds it and appended to `file_name` in the listed order.
  • Blocks already in `file_name` that are NOT in `desired_order` are left untouched at the top of the file.
  • An address that does not resolve to a known block is a hard error (silent skip would mask drift, since `desired_order` is usually computed from a data source).

func (*SortBlocksInFileTransform) Apply

func (s *SortBlocksInFileTransform) Apply() error

func (*SortBlocksInFileTransform) Type

type TerraformCliProviderSchemaRetriever

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

func (TerraformCliProviderSchemaRetriever) Get

func (t TerraformCliProviderSchemaRetriever) Get(providerSource, versionConstraint string) (*tfjson.ProviderSchema, error)

type TerraformData

type TerraformData struct {
	*BaseData
	*golden.BaseBlock

	RequiredVersion   *string                     `attribute:"required_version"`
	RequiredProviders map[string]RequiredProvider `attribute:"required_providers"`
	Block             cty.Value                   `attribute:"block"`
}

func (*TerraformData) ExecuteDuringPlan

func (d *TerraformData) ExecuteDuringPlan() error

func (*TerraformData) Type

func (d *TerraformData) Type() string

type TerraformModuleRef

type TerraformModuleRef struct {
	Key     string `json:"Key"`
	Source  string `json:"Source"`
	Dir     string `json:"Dir"`
	AbsDir  string
	Version string `json:"Version"`
	GitHash string
}

func ModuleRefs

func ModuleRefs(tfDir string) ([]*TerraformModuleRef, error)

func NewTerraformModuleRef

func NewTerraformModuleRef(dir, key, source, version string) (*TerraformModuleRef, error)

func NewTerraformRootModuleRef

func NewTerraformRootModuleRef(dir string) (*TerraformModuleRef, error)

func (*TerraformModuleRef) Load

func (m *TerraformModuleRef) Load() error

func (*TerraformModuleRef) LoadAbsDir

func (m *TerraformModuleRef) LoadAbsDir() error

func (*TerraformModuleRef) LoadGitHash

func (m *TerraformModuleRef) LoadGitHash()

type TerraformProviderSchemaRetriever

type TerraformProviderSchemaRetriever interface {
	Get(providerSource, versionConstraint string) (*tfjson.ProviderSchema, error)
}

func NewTerraformCliProviderSchemaRetriever

func NewTerraformCliProviderSchemaRetriever(ctx context.Context) TerraformProviderSchemaRetriever

type Transform

type Transform interface {
	golden.ApplyBlock
	Transform()
}

type UpdateInPlaceTransform

type UpdateInPlaceTransform struct {
	*golden.BaseBlock
	*BaseTransform
	TargetBlockAddress string `hcl:"target_block_address" validate:"required"`
	DynamicBlockBody   string `hcl:"dynamic_block_body,optional"`
	// contains filtered or unexported fields
}

func (*UpdateInPlaceTransform) Apply

func (u *UpdateInPlaceTransform) Apply() error

func (*UpdateInPlaceTransform) Decode

func (u *UpdateInPlaceTransform) Decode(block *golden.HclBlock, context *hcl.EvalContext) error

func (*UpdateInPlaceTransform) PatchWriteBlock

func (u *UpdateInPlaceTransform) PatchWriteBlock(dest terraform.Block, patch *hclwrite.Block)

func (*UpdateInPlaceTransform) String

func (u *UpdateInPlaceTransform) String() string

func (*UpdateInPlaceTransform) Type

func (u *UpdateInPlaceTransform) Type() string

func (*UpdateInPlaceTransform) UpdateBlock

func (u *UpdateInPlaceTransform) UpdateBlock() *hclwrite.Block

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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