terraform

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 73 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ResourceRegistryMap = buildResourceRegistryMap()
)

Functions

func Cmd

func Cmd(opts *CmdOptions, args ...string) ([]byte, error)

func CreateConfigFile

func CreateConfigFile(dir string, terraformCloudHost string, terraformCloudToken string) (string, error)

func GetUsageOnlyResources

func GetUsageOnlyResources() []string

func IsTerraformDir

func IsTerraformDir(path string) bool

func NewDirProvider

func NewDirProvider(ctx *settings.ProjectSession, includePastResources bool) engine.Vendor

func NewPlanProvider

func NewPlanProvider(ctx *settings.ProjectSession, includePastResources bool) engine.Vendor

func NewStateJSONProvider

func NewStateJSONProvider(ctx *settings.ProjectSession, includePastResources bool) engine.Vendor

func NewTerragruntHCLProvider

func NewTerragruntHCLProvider(rootPath hcl.RootPath, ctx *settings.ProjectSession) engine.Vendor

NewTerragruntHCLProvider creates a new provider initialized with the configured project path (usually the terragrunt root directory).

func NewTerragruntProvider

func NewTerragruntProvider(ctx *settings.ProjectSession, includePastResources bool) engine.Vendor

func ReadPlanCache

func ReadPlanCache(p *DirProvider) ([]byte, error)

func StripSetupTerraformWrapper

func StripSetupTerraformWrapper(b []byte) ([]byte, bool)

StripSetupTerraformWrapper removes any output added from the setup-terraform GitHub action terraform wrapper, so we can parse the output of this as valid JSON. It returns the stripped out JSON and a boolean that is true if the wrapper output was found and removed.

func UsePlanCache

func UsePlanCache(p *DirProvider) bool

func WritePlanCache

func WritePlanCache(p *DirProvider, planJSON []byte)

Types

type CmdError

type CmdError struct {
	Stderr []byte
	// contains filtered or unexported fields
}

func (*CmdError) Error

func (e *CmdError) Error() string

type CmdOptions

type CmdOptions struct {
	TerraformBinary     string
	Dir                 string
	TerraformWorkspace  string
	TerraformConfigFile string
	Env                 map[string]string
	Flags               []string
}

type ConfLoader

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

func NewConfLoader

func NewConfLoader(conf gjson.Result) *ConfLoader

func (*ConfLoader) GetModuleConfJSON

func (l *ConfLoader) GetModuleConfJSON(names []string) gjson.Result

func (*ConfLoader) GetResourceConfJSON

func (l *ConfLoader) GetResourceConfJSON(addr string) gjson.Result

type Configuration

type Configuration struct {
	ProviderConfig map[string]ProviderConfig `json:"provider_config"`
	RootModule     ModuleConfig              `json:"root_module"`
}

type DirProvider

type DirProvider struct {
	Path                string
	IsTerragrunt        bool
	PlanFlags           string
	InitFlags           string
	Workspace           string
	UseState            bool
	TerraformBinary     string
	TerraformCloudHost  string
	TerraformCloudToken string
	Env                 map[string]string
	// contains filtered or unexported fields
}

func (*DirProvider) AddMetadata

func (p *DirProvider) AddMetadata(metadata *engine.WorkspaceMeta)

func (*DirProvider) Context

func (p *DirProvider) Context() *settings.ProjectSession

func (*DirProvider) DisplayType

func (p *DirProvider) DisplayType() string

func (*DirProvider) LoadResources

func (p *DirProvider) LoadResources(usage engine.ConsumptionMap) ([]*engine.Workspace, error)

func (*DirProvider) ProjectName

func (p *DirProvider) ProjectName() string

func (*DirProvider) RelativePath

func (p *DirProvider) RelativePath() string

func (*DirProvider) Type

func (p *DirProvider) Type() string

func (*DirProvider) VarFiles

func (p *DirProvider) VarFiles() []string

type HCLLoader

type HCLLoader struct {
	Parser *hcl.Parser
	// contains filtered or unexported fields
}

func NewHCLProvider

func NewHCLProvider(ctx *settings.ProjectSession, rootPath hcl.RootPath, config *HCLProviderConfig, opts ...hcl.Option) (*HCLLoader, error)

NewHCLProvider returns a HCLProvider with a hcl.Parser initialised using the settings.ProjectSession. It will use input flags from either the terraform-plan-flags or top level var and var-file flags to set input vars and files on the underlying hcl.Parser.

func (*HCLLoader) AddMetadata

func (p *HCLLoader) AddMetadata(metadata *engine.WorkspaceMeta)

func (*HCLLoader) Context

func (p *HCLLoader) Context() *settings.ProjectSession

func (*HCLLoader) DependencyPaths

func (p *HCLLoader) DependencyPaths() []string

func (*HCLLoader) DisplayType

func (p *HCLLoader) DisplayType() string

func (*HCLLoader) EnvName

func (p *HCLLoader) EnvName() string

func (*HCLLoader) InvalidateCache

func (p *HCLLoader) InvalidateCache() *HCLLoader

InvalidateCache removes the module cache from the prior hcl parse.

func (*HCLLoader) LoadPlanJSON

func (p *HCLLoader) LoadPlanJSON() HCLProject

LoadPlanJSON parses the RootPath and return the blocks in Terraform plan JSON format.

func (*HCLLoader) LoadResources

func (p *HCLLoader) LoadResources(usage engine.ConsumptionMap) ([]*engine.Workspace, error)

LoadResources calls a hcl.Parser to parse the directory config files into hcl.Blocks. It then builds a shallow representation of the terraform plan JSON files from these Blocks, this is passed to the PlanJSONProvider. The PlanJSONProvider uses this shallow representation to actually load C3X resources.

func (*HCLLoader) Module

func (p *HCLLoader) Module() HCLProject

Module parses the RootPath into an hcl Module representing a config tree of Terraform information. Module returns the raw hcl blocks associated with each found Terraform project. This can be used to fetch raw information like outputs, vars, resources, e.t.c.

func (*HCLLoader) ProjectName

func (p *HCLLoader) ProjectName() string

func (*HCLLoader) RelativePath

func (p *HCLLoader) RelativePath() string

func (*HCLLoader) Type

func (p *HCLLoader) Type() string

func (*HCLLoader) VarFiles

func (p *HCLLoader) VarFiles() []string

func (*HCLLoader) YAML

func (p *HCLLoader) YAML() string

type HCLProject

type HCLProject struct {
	JSON   []byte
	Module *hcl.Module
	Error  error
}

type HCLProviderConfig

type HCLProviderConfig struct {
	SuppressLogging     bool
	CacheParsingModules bool
	SkipAutoDetection   bool
}

type MalformedRegistryURLErr

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

MalformedRegistryURLErr is returned if the Terraform Registry URL passed to the Getter is malformed.

func (MalformedRegistryURLErr) Error

func (err MalformedRegistryURLErr) Error() string

type ModuleCall

type ModuleCall struct {
	Source       string       `json:"source"`
	ModuleConfig ModuleConfig `json:"module"`
	SourceUrl    string       `json:"sourceUrl,omitempty"`
}

type ModuleConfig

type ModuleConfig struct {
	Resources   []ResourceData        `json:"resources,omitempty"`
	ModuleCalls map[string]ModuleCall `json:"module_calls,omitempty"`
}

type ModuleDownloadErr

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

ModuleDownloadErr is returned if Terragrunt failed to download the module.

func (ModuleDownloadErr) Error

func (err ModuleDownloadErr) Error() string

type ModuleOut

type ModuleOut struct {
	PlanModule   PlanModule
	ModuleConfig ModuleConfig
}

type ParsedPlanConfiguration

type ParsedPlanConfiguration struct {
	PastResources        []*engine.UnpricedEntry
	PastResourceDatas    []*engine.ResourceSpec
	CurrentResources     []*engine.UnpricedEntry
	CurrentResourceDatas []*engine.ResourceSpec
	ProviderMetadata     []engine.VendorMeta
	RemoteModuleCalls    []string
}

type Parser

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

func NewParser

func NewParser(ctx *settings.ProjectSession, includePastResources bool) *Parser

type PlanJSONProvider

type PlanJSONProvider struct {
	Path string
	// contains filtered or unexported fields
}

func NewPlanJSONProvider

func NewPlanJSONProvider(ctx *settings.ProjectSession, includePastResources bool) *PlanJSONProvider

func (*PlanJSONProvider) AddMetadata

func (p *PlanJSONProvider) AddMetadata(metadata *engine.WorkspaceMeta)

func (*PlanJSONProvider) Context

func (*PlanJSONProvider) DisplayType

func (p *PlanJSONProvider) DisplayType() string

func (*PlanJSONProvider) LoadResources

func (p *PlanJSONProvider) LoadResources(usage engine.ConsumptionMap) ([]*engine.Workspace, error)

func (*PlanJSONProvider) LoadResourcesFromSrc

func (p *PlanJSONProvider) LoadResourcesFromSrc(usage engine.ConsumptionMap, j []byte) (*engine.Workspace, error)

func (*PlanJSONProvider) ProjectName

func (p *PlanJSONProvider) ProjectName() string

func (*PlanJSONProvider) RelativePath

func (p *PlanJSONProvider) RelativePath() string

func (*PlanJSONProvider) Type

func (p *PlanJSONProvider) Type() string

func (*PlanJSONProvider) VarFiles

func (p *PlanJSONProvider) VarFiles() []string

type PlanModule

type PlanModule struct {
	Resources    []ResourceJSON `json:"resources,omitempty"`
	Address      *string        `json:"address,omitempty"`
	ChildModules []PlanModule   `json:"child_modules,omitempty"`
}

type PlanProvider

type PlanProvider struct {
	*DirProvider
	Path string
	// contains filtered or unexported fields
}

func (*PlanProvider) DisplayType

func (p *PlanProvider) DisplayType() string

func (*PlanProvider) LoadResources

func (p *PlanProvider) LoadResources(usage engine.ConsumptionMap) (projects []*engine.Workspace, err error)

func (*PlanProvider) ProjectName

func (p *PlanProvider) ProjectName() string

func (*PlanProvider) RelativePath

func (p *PlanProvider) RelativePath() string

func (*PlanProvider) Type

func (p *PlanProvider) Type() string

func (*PlanProvider) VarFiles

func (p *PlanProvider) VarFiles() []string

type PlanSchema

type PlanSchema struct {
	FormatVersion    string      `json:"format_version"`
	TerraformVersion string      `json:"terraform_version"`
	Variables        interface{} `json:"variables,omitempty"`
	PriorState       struct {
		Values PlanValues `json:"values"`
	} `json:"prior_state"`
	PlannedValues PlanValues    `json:"planned_values"`
	Configuration Configuration `json:"configuration"`

	// C3XResourceChanges is a flattened list of resource changes for the plan, this is in the format of the Terraform
	// plan JSON output, but we omit adding it as the supported `resource_changes` key as this will cause plan inconsistencies.
	// We copy this `c3x_resource_changes` key at a later date to `resource_changes` before sending to the Policy API.
	// This means that we can evaluate the Rego ruleset on the known Terraform plan JSON structure.
	C3XResourceChanges     []ResourceChangesJSON   `json:"c3x_resource_changes"`
	C3XProviderConstraints hcl.ProviderConstraints `json:"c3x_provider_constraints"`
}

type PlanValues

type PlanValues struct {
	RootModule PlanModule `json:"root_module"`
}

type ProviderConfig

type ProviderConfig struct {
	Name        string                 `json:"name"`
	Expressions map[string]interface{} `json:"expressions,omitempty"`
	C3XMetadata map[string]interface{} `json:"c3x_metadata"`
}

type RegistryAPIErr

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

RegistryAPIErr is returned if we get an unsuccessful HTTP return code from the registry.

func (RegistryAPIErr) Error

func (err RegistryAPIErr) Error() string

type RegistryItemMap

type RegistryItemMap map[string]*engine.CatalogEntry

func (*RegistryItemMap) GetCustomRefIDFunc

func (r *RegistryItemMap) GetCustomRefIDFunc(resourceDataType string) engine.ReferenceIDFunc

func (*RegistryItemMap) GetDefaultRefIDFunc

func (r *RegistryItemMap) GetDefaultRefIDFunc(resourceDataType string) engine.ReferenceIDFunc

func (*RegistryItemMap) GetReferenceAttributes

func (r *RegistryItemMap) GetReferenceAttributes(resourceDataType string) []string

func (*RegistryItemMap) GetRegion

func (r *RegistryItemMap) GetRegion(resourceDataType string) engine.RegionLookupFunc

GetRegion returns the region lookup function for the given resource data type if it exists.

type ResourceChange

type ResourceChange struct {
	Actions []string               `json:"actions"`
	Before  interface{}            `json:"before"`
	After   map[string]interface{} `json:"after"`
}

type ResourceChangesJSON

type ResourceChangesJSON struct {
	Address       string         `json:"address"`
	ModuleAddress *string        `json:"module_address,omitempty"`
	Mode          string         `json:"mode"`
	Type          string         `json:"type"`
	Name          string         `json:"name"`
	Index         *int64         `json:"index,omitempty"`
	Change        ResourceChange `json:"change"`
}

type ResourceData

type ResourceData struct {
	Address           string                 `json:"address"`
	Mode              string                 `json:"mode"`
	Type              string                 `json:"type"`
	Name              string                 `json:"name"`
	ProviderConfigKey string                 `json:"provider_config_key"`
	Expressions       map[string]interface{} `json:"expressions,omitempty"`
	SchemaVersion     int                    `json:"schema_version"`
	CountExpression   *countExpression       `json:"count_expression,omitempty"`
}

type ResourceJSON

type ResourceJSON struct {
	Address       string                 `json:"address"`
	Mode          string                 `json:"mode"`
	Type          string                 `json:"type"`
	Name          string                 `json:"name"`
	Index         *int64                 `json:"index,omitempty"`
	SchemaVersion int                    `json:"schema_version"`
	Values        map[string]interface{} `json:"values"`
	C3XMetadata   map[string]interface{} `json:"c3x_metadata"`
}

type ResourceOutput

type ResourceOutput struct {
	Planned       ResourceJSON
	Changes       ResourceChangesJSON
	PriorState    ResourceJSON
	Configuration ResourceData
}

type RunShowOptions

type RunShowOptions struct {
	CmdOptions *CmdOptions
}

type ServiceDiscoveryErr

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

ServiceDiscoveryErr is returned if Terragrunt failed to identify the module API endpoint through the service discovery protocol.

func (ServiceDiscoveryErr) Error

func (err ServiceDiscoveryErr) Error() string

type StateJSONProvider

type StateJSONProvider struct {
	Path string
	// contains filtered or unexported fields
}

func (*StateJSONProvider) AddMetadata

func (p *StateJSONProvider) AddMetadata(metadata *engine.WorkspaceMeta)

func (*StateJSONProvider) Context

func (*StateJSONProvider) DisplayType

func (p *StateJSONProvider) DisplayType() string

func (*StateJSONProvider) LoadResources

func (p *StateJSONProvider) LoadResources(usage engine.ConsumptionMap) ([]*engine.Workspace, error)

func (*StateJSONProvider) ProjectName

func (p *StateJSONProvider) ProjectName() string

func (*StateJSONProvider) RelativePath

func (p *StateJSONProvider) RelativePath() string

func (*StateJSONProvider) Type

func (p *StateJSONProvider) Type() string

func (*StateJSONProvider) VarFiles

func (p *StateJSONProvider) VarFiles() []string

type TerraformRegistryGetter

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

TerraformRegistryGetter is a Getter (from modsource) implementation that will download from the terraform module registry. This supports getter URLs encoded in the following manner:

tfr://REGISTRY_DOMAIN/MODULE_PATH?version=VERSION

Where the REGISTRY_DOMAIN is the terraform registry endpoint (e.g., registry.terraform.io), MODULE_PATH is the registry path for the module (e.g., terraform-aws-modules/vpc/aws), and VERSION is the specific version of the module to download (e.g., 2.2.0).

This protocol will use the Module Registry Protocol (documented at https://www.terraform.io/docs/internals/module-registry-protocol.html) to lookup the module source URL and download it.

Authentication to private module registries is handled via environment variables. The authorization API token is expected to be provided to Terragrunt via the TG_TF_REGISTRY_TOKEN environment variable. This token can be any registry API token generated on Terraform Cloud / Enterprise.

MAINTAINER'S NOTE: Ideally we implement the full credential system that terraform uses as part of `terraform login`, but all the relevant packages are internal to the terraform repository, thus making it difficult to use as a library. For now, we keep things simple by supporting providing tokens via env vars and in the future, we can consider implementing functionality to load credentials from terraform. See: https://github.com/c3xdev/c3x/issues/1771

MAINTAINER'S NOTE: Ideally we can support a shorthand notation that omits the tfr:// protocol to detect that it is referring to a terraform registry, but this requires implementing a complex detector and ensuring it has precedence over the file detector. We deferred the implementation for that to a future release. See: https://github.com/c3xdev/c3x/issues/1772

func (*TerraformRegistryGetter) ClientMode

func (tfrGetter *TerraformRegistryGetter) ClientMode(ctx context.Context, u *url.URL) (getter.ClientMode, error)

ClientMode returns the download mode based on the given URL. Since this getter is designed around the Terraform module registry, we always use Dir mode so that we can download the full Terraform module.

func (*TerraformRegistryGetter) Get

func (tfrGetter *TerraformRegistryGetter) Get(ctx context.Context, dstPath string, srcURL *url.URL) error

Get is the main routine to fetch the module contents specified at the given URL and download it to the dstPath. This routine assumes that the srcURL points to the Terraform registry URL, with the Path configured to the module path encoded as `:namespace/:name/:system` as expected by the Terraform registry. Note that the URL query parameter must have the `version` key to specify what version to download.

func (*TerraformRegistryGetter) GetFile

func (tfrGetter *TerraformRegistryGetter) GetFile(dst string, src *url.URL) error

GetFile is not implemented for the Terraform module registry Getter since the terraform module registry doesn't serve a single file.

func (*TerraformRegistryGetter) SetClient

func (tfrGetter *TerraformRegistryGetter) SetClient(client *getter.Client)

SetClient allows the getter to know what getter client (different from the underlying HTTP client) to use for progress tracking.

type TerraformRegistryServicePath

type TerraformRegistryServicePath struct {
	ModulesPath string `json:"modules.v1"`
}

TerraformRegistryServicePath is a struct for extracting the modules service path in the Registry.

type TerragruntHCLProvider

type TerragruntHCLProvider struct {
	Path hcl.RootPath
	// contains filtered or unexported fields
}

func (*TerragruntHCLProvider) AddMetadata

func (p *TerragruntHCLProvider) AddMetadata(metadata *engine.WorkspaceMeta)

func (*TerragruntHCLProvider) Context

func (*TerragruntHCLProvider) DependencyPaths

func (p *TerragruntHCLProvider) DependencyPaths() []string

func (*TerragruntHCLProvider) DisplayType

func (p *TerragruntHCLProvider) DisplayType() string

func (*TerragruntHCLProvider) EnvName

func (p *TerragruntHCLProvider) EnvName() string

func (*TerragruntHCLProvider) LoadResources

func (p *TerragruntHCLProvider) LoadResources(usage engine.ConsumptionMap) ([]*engine.Workspace, error)

LoadResources finds any Terragrunt projects, prepares them by downloading any required source files, then process each with an HCLProvider.

func (*TerragruntHCLProvider) ProjectName

func (p *TerragruntHCLProvider) ProjectName() string

func (*TerragruntHCLProvider) RelativePath

func (p *TerragruntHCLProvider) RelativePath() string

func (*TerragruntHCLProvider) Type

func (p *TerragruntHCLProvider) Type() string

func (*TerragruntHCLProvider) VarFiles

func (p *TerragruntHCLProvider) VarFiles() []string

func (*TerragruntHCLProvider) YAML

func (p *TerragruntHCLProvider) YAML() string

type TerragruntInfo

type TerragruntInfo struct {
	ConfigPath string
	WorkingDir string
}

type TerragruntOutputCache

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

func (*TerragruntOutputCache) Set

func (o *TerragruntOutputCache) Set(key string, getVal func() (cty.Value, error)) (cty.Value, error)

Set stores a value in the cache for the given key using the value returned from getVal function. If the key already exists in the cache, the value is returned from the cache.

type TerragruntProvider

type TerragruntProvider struct {
	Path            string
	TerragruntFlags string
	*DirProvider
	// contains filtered or unexported fields
}

func (*TerragruntProvider) AddMetadata

func (p *TerragruntProvider) AddMetadata(metadata *engine.WorkspaceMeta)

func (*TerragruntProvider) Context

func (*TerragruntProvider) DisplayType

func (p *TerragruntProvider) DisplayType() string

func (*TerragruntProvider) LoadResources

func (p *TerragruntProvider) LoadResources(usage engine.ConsumptionMap) ([]*engine.Workspace, error)

func (*TerragruntProvider) ProjectName

func (p *TerragruntProvider) ProjectName() string

func (*TerragruntProvider) RelativePath

func (p *TerragruntProvider) RelativePath() string

func (*TerragruntProvider) Type

func (p *TerragruntProvider) Type() string

func (*TerragruntProvider) VarFiles

func (p *TerragruntProvider) VarFiles() []string

type YorConfig

type YorConfig struct {
	Name  string `yaml:"name"`
	Value struct {
		Default string `yaml:"default"`
	} `yaml:"value"`
	TagGroups []struct {
		Name string `yaml:"name"`
		Tags []struct {
			Name  string `yaml:"name"`
			Value struct {
				Default string `yaml:"default"`
			} `yaml:"value"`
		} `yaml:"tags"`
	} `yaml:"tag_groups"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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