Movatterモバイル変換


[0]ホーム

URL:


tfconfig

package
v0.0.0-...-f4c50e6Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License:MPL-2.0Imports:21Imported by:134

Details

Repository

github.com/hashicorp/terraform-config-inspect

Links

Documentation

Overview

Package tfconfig is a helper library that does careful, shallow parsing ofTerraform modules to provide access to high-level metadata whileremaining broadly compatible with configurations targeting variousdifferent Terraform versions.

This package focuses on describing top-level objects only, and in particulardoes not attempt any sort of processing that would require access to plugins.Currently it allows callers to extract high-level information aboutvariables, outputs, resource blocks, provider dependencies, and TerraformCore dependencies.

This package only works at the level of single modules. A full configurationis a tree of potentially several modules, some of which may be referencesto remote packages. There are some basic helpers for traversing calls tomodules at relative local paths, however.

This package employs a "best effort" parsing strategy, producing as completea result as possible even though the input may not be entirely valid. Theintended use-case is high-level analysis and indexing of externally-facingmodule characteristics, as opposed to validating or even applying the module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcIsModuleDir

func IsModuleDir(dirstring)bool

IsModuleDir checks if the given path contains terraform configuration files.This allows the caller to decide how to handle directories that do not have tf files.

funcIsModuleDirOnFilesystem

func IsModuleDirOnFilesystem(fsFS, dirstring)bool

IsModuleDirOnFilesystem checks if the given path in the given FS containsTerraform configuration files. This allows the caller to decidehow to handle directories that do not have tf files.

funcLoadModule

func LoadModule(dirstring) (*Module,Diagnostics)

LoadModule reads the directory at the given path and attempts to interpretit as a Terraform module.

funcLoadModuleFromFile

func LoadModuleFromFile(file *hcl.File, mod *Module) hcl.Diagnostics

LoadModuleFromFile reads given file, interprets it and stores in given ModuleThis is useful for any caller which does tokenization/parsing on its owne.g. because it will reuse these parsed files later for more detailedinterpretation.

funcLoadModuleFromFilesystem

func LoadModuleFromFilesystem(fsFS, dirstring) (*Module,Diagnostics)

LoadModuleFromFilesystem reads the directory at the given pathin the given FS and attempts to interpret it as a Terraform module

funcRenderMarkdown

func RenderMarkdown(wio.Writer, module *Module)error

Types

typeDiagSeverity

type DiagSeverityrune

DiagSeverity describes the severity of a Diagnostic.

const DiagErrorDiagSeverity = 'E'

DiagError indicates a problem that prevented proper processing of theconfiguration. In the precense of DiagError diagnostics the result islikely to be incomplete.

const DiagWarningDiagSeverity = 'W'

DiagWarning indicates a problem that the user may wish to consider butthat did not prevent proper processing of the configuration.

func (DiagSeverity)MarshalJSON

func (sDiagSeverity) MarshalJSON() ([]byte,error)

MarshalJSON is an implementation of encoding/json.Marshaler

typeDiagnostic

type Diagnostic struct {SeverityDiagSeverity `json:"severity"`Summarystring       `json:"summary"`Detailstring       `json:"detail,omitempty"`// Pos is not populated for all diagnostics, but when populated should// indicate a particular line that the described problem relates to.Pos *SourcePos `json:"pos,omitempty"`}

Diagnostic describes a problem (error or warning) encountered duringconfiguration loading.

typeDiagnostics

type Diagnostics []Diagnostic

Diagnostics represents a sequence of diagnostics. This is the type thatshould be returned from a function that might generate diagnostics.

func (Diagnostics)Err

func (diagsDiagnostics) Err()error

Err returns an error representing the receiver if the receiver HasErrors, ornil otherwise.

The returned error can be type-asserted back to a Diagnostics if needed.

func (Diagnostics)Error

func (diagsDiagnostics) Error()string

func (Diagnostics)HasErrors

func (diagsDiagnostics) HasErrors()bool

HasErrors returns true if there is at least one Diagnostic of severityDiagError in the receiever.

If a function returns a Diagnostics without errors then the result canbe assumed to be complete within the "best effort" constraints of thislibrary. If errors are present then the caller may wish to employ morecaution in relying on the result.

typeFS

type FS interface {Open(namestring) (File,error)ReadFile(namestring) ([]byte,error)ReadDir(dirnamestring) ([]os.FileInfo,error)}

FS is an interface used byLoadModuleFromFilesystem.

Unfortunately this package implemented a draft version of the io/fs.FSAPI before it was finalized and so this interface is not compatible withthe final design. To use this package with the final filesystem API design,useWrapFS to wrap a standard filesystem implementation so that itimplements this interface.

funcNewOsFs

func NewOsFs()FS

NewOsFs provides a basic implementation of FS for an OS filesystem

funcWrapFS

func WrapFS(wrappedfs.FS)FS

WrapFS wraps a standard library filesystem implementation so that itimplements this package's own (slightly-incompatible) interfaceFS.

typeFile

type File interface {Stat() (os.FileInfo,error)Read([]byte) (int,error)Close()error}

File represents an open file inFS.

typeModule

type Module struct {// Path is the local filesystem directory where the module was loaded from.Pathstring `json:"path"`Variables map[string]*Variable `json:"variables"`Outputs   map[string]*Output   `json:"outputs"`RequiredCore      []string                        `json:"required_core,omitempty"`RequiredProviders map[string]*ProviderRequirement `json:"required_providers"`ProviderConfigs  map[string]*ProviderConfig `json:"provider_configs,omitempty"`ManagedResources map[string]*Resource       `json:"managed_resources"`DataResources    map[string]*Resource       `json:"data_resources"`ModuleCalls      map[string]*ModuleCall     `json:"module_calls"`// Diagnostics records any errors and warnings that were detected during// loading, primarily for inclusion in serialized forms of the module// since this slice is also returned as a second argument from LoadModule.DiagnosticsDiagnostics `json:"diagnostics,omitempty"`}

Module is the top-level type representing a parsed and processed Terraformmodule.

funcNewModule

func NewModule(pathstring) *Module

NewModule creates new Module representing Terraform module at the given path

typeModuleCall

type ModuleCall struct {Namestring `json:"name"`Sourcestring `json:"source"`Versionstring `json:"version,omitempty"`PosSourcePos `json:"pos"`}

ModuleCall represents a "module" block within a module. That is, adeclaration of a child module from inside its parent.

typeOutput

type Output struct {Namestring    `json:"name"`Descriptionstring    `json:"description,omitempty"`Sensitivebool      `json:"sensitive,omitempty"`PosSourcePos `json:"pos"`}

Output represents a single output from a Terraform module.

typeProviderConfig

type ProviderConfig struct {Namestring `json:"name"`Aliasstring `json:"alias,omitempty"`}

ProviderConfig represents a provider block in the configuration

typeProviderRef

type ProviderRef struct {Namestring `json:"name"`Aliasstring `json:"alias,omitempty"`// Empty if the default provider configuration is referenced}

ProviderRef is a reference to a provider configuration within a module.It represents the contents of a "provider" argument in a resource, ora value in the "providers" map for a module call.

typeProviderRequirement

type ProviderRequirement struct {Sourcestring        `json:"source,omitempty"`VersionConstraints   []string      `json:"version_constraints,omitempty"`ConfigurationAliases []ProviderRef `json:"aliases,omitempty"`}

typeResource

type Resource struct {ModeResourceMode `json:"mode"`Typestring       `json:"type"`Namestring       `json:"name"`ProviderProviderRef `json:"provider"`PosSourcePos `json:"pos"`}

Resource represents a single "resource" or "data" block within a module.

func (*Resource)MapKey

func (r *Resource) MapKey()string

MapKey returns a string that can be used to uniquely identify the receiverin a map[string]*Resource.

typeResourceMode

type ResourceModerune

ResourceMode represents the "mode" of a resource, which is used todistinguish between managed resources ("resource" blocks in config) anddata resources ("data" blocks in config).

const DataResourceModeResourceMode = 'D'
const InvalidResourceModeResourceMode = 0
const ManagedResourceModeResourceMode = 'M'

func (ResourceMode)MarshalJSON

func (mResourceMode) MarshalJSON() ([]byte,error)

MarshalJSON implements encoding/json.Marshaler.

func (ResourceMode)String

func (mResourceMode) String()string

typeSourcePos

type SourcePos struct {Filenamestring `json:"filename"`Lineint    `json:"line"`}

SourcePos is a pointer to a particular location in a source file.

This type is embedded into other structs to allow callers to locate thedefinition of each described module element. The SourcePos of an elementis usually the first line of its definition, although the definition canbe a little "fuzzy" with JSON-based config files.

typeVariable

type Variable struct {Namestring `json:"name"`Typestring `json:"type,omitempty"`Descriptionstring `json:"description,omitempty"`// Default is an approximate representation of the default value in// the native Go type system. The conversion from the value given in// configuration may be slightly lossy. Only values that can be// serialized by json.Marshal will be included here.Default   interface{} `json:"default"`Requiredbool        `json:"required"`Sensitivebool        `json:"sensitive,omitempty"`PosSourcePos `json:"pos"`}

Variable represents a single variable from a Terraform module.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp