provider

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package provider understands the layout of terraform provider repositories: classifying changed files, extracting acceptance tests, and tracing symbols and imports via the Go AST.

Index

Constants

View Source
const (
	FileColourOther    = "<darkGray>"
	FileColourResource = "<fg=36>"
	FileColourHelper   = "<fg=117>"
	FileColourTest     = "<fg=28>"
	FileColourUnitTest = "<darkGray>"
	FileColourVendor   = "<fg=177>"
	FileColourDerived  = "<fg=36>"
	FileColourSkipped  = "<red>"
)

Variables

View Source
var Classifier = DefaultClassifier

Classifier sets the file type for a File. It can be overridden at program start to provide custom logic.

View Source
var ServiceDirPrefixes = []string{"internal/services", "internal/service"}

ServiceDirPrefixes lists the path segments used by different providers to organise service packages. Azure uses "internal/services/", AWS uses "internal/service/". All code that needs to detect or enumerate service directories should iterate over this slice.

Functions

func GetModulePath

func GetModulePath(repoPath string) (string, error)

GetModulePath reads go.mod in the repo and returns the module import path.

func SymbolsFromAST added in v1.0.1

func SymbolsFromAST(parsed *ast.File, exportedOnly bool) []string

SymbolsFromAST extracts all globally declared function/type/variable/constant names from an already-parsed file. If exportedOnly is true, it only returns exported names.

Types

type File

type File struct {
	RelPath      string // full relative path: "internal/services/batch/batch_account_resource.go"
	Path         string // absolute local path (or empty if using Content buffer)
	Dir          string // directory with trailing slash: "internal/services/batch/"
	Name         string // filename: "batch_account_resource.go"
	BaseName     string // filename without .go: "batch_account_resource"
	Service      string // the extracted service name from the path, e.g. "batch"
	Type         FileType
	DiscoveredBy []string // e.g. CHANGED, DERIVED, TRACED, VENDOR
	// contains filtered or unexported fields
}

File represents a Go source file in a Terraform provider repository.

func NewFile

func NewFile(relPath string) File

NewFile creates a File with only the path-derived fields populated. Use this for files in a remote environment where a local disk path isn't applicable.

func NewFileWithPath

func NewFileWithPath(relPath, repoPath string) File

NewFileWithPath creates a File from a relative path and a local repository root.

func (*File) AddDiscovery

func (f *File) AddDiscovery(source string)

AddDiscovery adds a discovery source label if it isn't already present.

func (*File) Classify

func (f *File) Classify() FileType

Classify determines the FileType for this file using the global Classifier and sets f.Type.

func (*File) ColouredFileName

func (f *File) ColouredFileName() string

ColouredFileName returns the formatted dir + coloured base for cout output. Example: "<fg=208>internal/services/batch/</><fg=36>batch_account_resource.go</>"

func (*File) ExtractTests

func (f *File) ExtractTests(splitOn string, reappend bool) ([]string, error)

ExtractTests parses Go source code and extracts names of acceptance tests (functions starting with "TestAcc"). If AST parsing fails, it falls back to string regex matching. It uses f.GetContent() to read the file (from cached Content or from disk). It also applies the provided `splitOn` and `reappend` logic.

func (*File) GetContent

func (f *File) GetContent() ([]byte, error)

GetContent returns the file's content. It uses the cached Content buffer if available, otherwise reads from the absolute Path on disk and caches the result.

func (*File) InServicePackage

func (f *File) InServicePackage() bool

InServicePackage returns true if the path is within a service directory.

func (*File) ResourcePrefix

func (f *File) ResourcePrefix() string

ResourcePrefix returns the prefix used for test file discovery. For "batch_account_resource.go" → "batch_account". For "batch_account_data_source.go" → "batch_account_data_source".

func (*File) SetContent

func (f *File) SetContent(content []byte)

SetContent sets the file's internal content buffer and re-runs classification.

func (*File) Symbols

func (f *File) Symbols(exportedOnly bool) []string

Symbols extracts all globally declared function/type/variable/constant names from the file. If exportedOnly is true, it only returns symbols starting with an uppercase letter.

func (*File) TextColour

func (f *File) TextColour() string

TextColour returns the cout colour tag for this file type.

func (*File) TypeLabel

func (f *File) TypeLabel() string

TypeLabel returns the display label for this file type (e.g. "[RESOURCE]", "[HELPER]").

type FileType

type FileType int

FileType classifies a Go file within a Terraform provider repository.

const (
	FileTypeOther    FileType = iota // outside service directories
	FileTypeResource                 // matches fileregex (resource or data source at service root)
	FileTypeHelper                   // in service dir but doesn't match fileregex (e.g. parse/, validate/, client/)
	FileTypeTest                     // _test.go with TestAcc functions
	FileTypeUnitTest                 // _test.go without TestAcc functions
	FileTypeVendor                   // under vendor/
)

func DefaultClassifier

func DefaultClassifier(f *File) FileType

DefaultClassifier provides the base classification logic.

Jump to

Keyboard shortcuts

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