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

terraform

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: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootBlockReflectionInformation = func(v map[string]cty.Value, b *RootBlock) {
	var moduleObj = cty.ObjectVal(map[string]cty.Value{
		"key":      cty.StringVal(""),
		"version":  cty.StringVal(""),
		"source":   cty.StringVal(""),
		"dir":      cty.StringVal(""),
		"abs_dir":  cty.StringVal(""),
		"git_hash": cty.StringVal(""),
	})
	if b.module != nil {
		moduleObj = cty.ObjectVal(map[string]cty.Value{
			"key":      cty.StringVal(b.module.Key),
			"version":  cty.StringVal(b.module.Version),
			"source":   cty.StringVal(b.module.Source),
			"dir":      cty.StringVal(b.module.Dir),
			"abs_dir":  cty.StringVal(b.module.AbsDir),
			"git_hash": cty.StringVal(b.module.GitHash),
		})
	}
	labels := golden.ToCtyValue(b.Labels)
	v["mptf"] = cty.ObjectVal(map[string]cty.Value{
		"block_address":     cty.StringVal(b.Address),
		"terraform_address": cty.StringVal(blockAddressToRef(b.Address)),
		"block_type":        cty.StringVal(b.Type),
		"block_labels":      labels,
		"module":            moduleObj,
		"range": cty.ObjectVal(map[string]cty.Value{
			"file_name":    cty.StringVal(b.Range().Filename),
			"start_line":   cty.NumberIntVal(int64(b.Range().Start.Line)),
			"start_column": cty.NumberIntVal(int64(b.Range().Start.Column)),
			"end_line":     cty.NumberIntVal(int64(b.Range().End.Line)),
			"end_column":   cty.NumberIntVal(int64(b.Range().End.Column)),
		}),
	})
}

Functions

func ListOfObject

func ListOfObject[T Object](objs []T) cty.Value

Types

type Attribute

type Attribute struct {
	Name string
	*hclsyntax.Attribute
	WriteAttribute *hclwrite.Attribute
}

func NewAttribute

func NewAttribute(name string, attribute *hclsyntax.Attribute, writeAttribute *hclwrite.Attribute) *Attribute

func (*Attribute) String

func (a *Attribute) String() string

type Block

type Block interface {
	EvalContext() cty.Value
	GetAttributes() map[string]*Attribute
	GetNestedBlocks() NestedBlocks
	WriteBody() *hclwrite.Body
	SetAttributeRaw(name string, tokens hclwrite.Tokens)
	AppendBlock(block *hclwrite.Block)
	Range() hcl.Range
	RemoveContent(path string)
}

type Module

type Module struct {
	Dir    string
	AbsDir string

	ResourceBlocks  []*RootBlock
	DataBlocks      []*RootBlock
	ModuleBlocks    []*RootBlock
	TerraformBlocks []*RootBlock
	Variables       []*RootBlock
	Outputs         []*RootBlock
	Locals          []*RootBlock
	MovedBlocks     []*RootBlock
	Key             string
	Source          string
	Version         string
	GitHash         string
	// contains filtered or unexported fields
}

func LoadModule

func LoadModule(mr ModuleRef) (*Module, error)

func (*Module) AddBlock

func (m *Module) AddBlock(fileName string, block *hclwrite.Block)

func (*Module) Blocks

func (m *Module) Blocks() []*RootBlock

func (*Module) RemoveBlock

func (m *Module) RemoveBlock(block *hclwrite.Block)

func (*Module) SaveToDisk

func (m *Module) SaveToDisk() error

type ModuleRef

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

type NestedBlock

type NestedBlock struct {
	Type string
	*hclsyntax.Block

	WriteBlock   *hclwrite.Block
	ForEach      *Attribute
	Iterator     *Attribute
	Attributes   map[string]*Attribute
	NestedBlocks NestedBlocks
	// contains filtered or unexported fields
}

func NewNestedBlock

func NewNestedBlock(rb *hclsyntax.Block, wb *hclwrite.Block) *NestedBlock

func (*NestedBlock) AppendBlock

func (nb *NestedBlock) AppendBlock(block *hclwrite.Block)

func (*NestedBlock) EvalContext

func (nb *NestedBlock) EvalContext() cty.Value

func (*NestedBlock) GetAttributes

func (nb *NestedBlock) GetAttributes() map[string]*Attribute

func (*NestedBlock) GetNestedBlocks

func (nb *NestedBlock) GetNestedBlocks() NestedBlocks

func (*NestedBlock) MptfObject

func (nb *NestedBlock) MptfObject() cty.Value

func (*NestedBlock) RemoveContent

func (nb *NestedBlock) RemoveContent(path string)

func (*NestedBlock) SetAttributeRaw

func (nb *NestedBlock) SetAttributeRaw(name string, tokens hclwrite.Tokens)

func (*NestedBlock) String

func (nb *NestedBlock) String() string

func (*NestedBlock) WriteBody

func (nb *NestedBlock) WriteBody() *hclwrite.Body

type NestedBlocks

type NestedBlocks map[string][]*NestedBlock

func (NestedBlocks) Values

func (nbs NestedBlocks) Values() map[string]cty.Value

type Object

type Object interface {
	EvalContext() cty.Value
}

type RootBlock

type RootBlock struct {
	*hclsyntax.Block

	WriteBlock   *hclwrite.Block
	Count        *Attribute
	ForEach      *Attribute
	Attributes   map[string]*Attribute
	NestedBlocks NestedBlocks
	Type         string
	Labels       []string
	Address      string
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(m *Module, rb *hclsyntax.Block, wb *hclwrite.Block) *RootBlock

func (*RootBlock) AppendBlock

func (b *RootBlock) AppendBlock(block *hclwrite.Block)

func (*RootBlock) EvalContext

func (b *RootBlock) EvalContext() cty.Value

func (*RootBlock) GetAttributes

func (b *RootBlock) GetAttributes() map[string]*Attribute

func (*RootBlock) GetNestedBlocks

func (b *RootBlock) GetNestedBlocks() NestedBlocks

func (*RootBlock) RemoveContent

func (b *RootBlock) RemoveContent(path string)

func (*RootBlock) SetAttributeRaw

func (b *RootBlock) SetAttributeRaw(name string, tokens hclwrite.Tokens)

func (*RootBlock) WriteBody

func (b *RootBlock) WriteBody() *hclwrite.Body

Jump to

Keyboard shortcuts

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