Documentation
¶
Index ¶
- Variables
- func ListOfObject[T Object](objs []T) cty.Value
- func SetNormalizeOptions(opts NormalizeOptions)
- func TestFilePath(moduleDir, filename string) (string, error)
- type Attribute
- type Block
- type Module
- type ModuleRef
- type NestedBlock
- func (nb *NestedBlock) AppendBlock(block *hclwrite.Block)
- func (nb *NestedBlock) EvalContext() cty.Value
- func (nb *NestedBlock) GetAttributes() map[string]*Attribute
- func (nb *NestedBlock) GetNestedBlocks() NestedBlocks
- func (nb *NestedBlock) MptfObject() cty.Value
- func (nb *NestedBlock) RemoveContent(path string)
- func (nb *NestedBlock) SetAttributeRaw(name string, tokens hclwrite.Tokens)
- func (nb *NestedBlock) String() string
- func (nb *NestedBlock) WriteBody() *hclwrite.Body
- type NestedBlocks
- type NormalizeOptions
- type Object
- type RootBlock
- func (b *RootBlock) AppendBlock(block *hclwrite.Block)
- func (b *RootBlock) EvalContext() cty.Value
- func (b *RootBlock) GetAttributes() map[string]*Attribute
- func (b *RootBlock) GetNestedBlocks() NestedBlocks
- func (b *RootBlock) RemoveContent(path string)
- func (b *RootBlock) SetAttributeRaw(name string, tokens hclwrite.Tokens)
- func (b *RootBlock) WriteBody() *hclwrite.Body
Constants ¶
This section is empty.
Variables ¶
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 SetNormalizeOptions ¶ added in v0.1.2
func SetNormalizeOptions(opts NormalizeOptions)
SetNormalizeOptions overrides the package-level options consulted by SaveToDisk when it calls normalizeFileWhitespace. Intended to be called once at startup from the CLI based on user flags. Not goroutine-safe; callers should set this before kicking off any transform that may write to disk.
func TestFilePath ¶ added in v0.3.0
TestFilePath resolves one test file relative to its owning module.
Types ¶
type Attribute ¶
func NewAttribute ¶
type Module ¶
type Module struct {
Dir string
AbsDir string
ResourceBlocks []*RootBlock
DataBlocks []*RootBlock
EphemeralBlocks []*RootBlock
ModuleBlocks []*RootBlock
TerraformBlocks []*RootBlock
Variables []*RootBlock
Outputs []*RootBlock
Locals []*RootBlock
MovedBlocks []*RootBlock
Key string
Source string
Version string
GitHash string
TestFile string
TestBlocks []*RootBlock
// contains filtered or unexported fields
}
func LoadModule ¶
func (*Module) RemoveBlock ¶
func (*Module) SaveToDisk ¶
func (*Module) ValidateTargetFile ¶ added in v0.3.0
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
type NormalizeOptions ¶ added in v0.1.2
type NormalizeOptions struct {
// KeepAdjacentSameKindUnlabeledBlocks, when true, suppresses the blank
// line between adjacent root-level blocks that have no labels AND share
// the same leading identifier (e.g. two `locals {}` or two `moved {}`).
// Labeled blocks (`variable "a" {}` and `variable "b" {}`, two `resource`
// blocks of the same type, etc.) are unaffected — they always get a
// blank line between them.
//
// Default false: every pair of root blocks gets exactly one blank line
// between them regardless of kind or label, matching the v0.1.1
// normalizer's behaviour. This is the safe default because most existing
// Terraform style guides and tooling pipelines expect a blank line
// between every root block.
//
// Set to true via the `--keep-adjacent-blocks` CLI flag when a target
// repository prefers grouping adjacent same-kind unlabeled blocks
// together (matches the way `terraform fmt` leaves hand-written
// adjacent `locals {}` blocks).
KeepAdjacentSameKindUnlabeledBlocks bool
}
NormalizeOptions tunes normalizeFileWhitespace's inter-block layout behaviour. The zero value is the default behaviour applied by SaveToDisk when no CLI override is provided.
func NormalizeOptionsValue ¶ added in v0.1.2
func NormalizeOptionsValue() NormalizeOptions
NormalizeOptionsValue returns the current package-level NormalizeOptions previously set via SetNormalizeOptions (or the zero value if none was set). Exposed for tests and diagnostic logging.
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 (*RootBlock) AppendBlock ¶
func (*RootBlock) EvalContext ¶
func (*RootBlock) GetAttributes ¶
func (*RootBlock) GetNestedBlocks ¶
func (b *RootBlock) GetNestedBlocks() NestedBlocks