terraform

package
v0.10.35 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 68 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmd added in v0.6.3

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

func CreateConfigFile added in v0.7.10

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

func GetUsageOnlyResources added in v0.7.12

func GetUsageOnlyResources() []string

func IsTerraformDir added in v0.8.0

func IsTerraformDir(path string) bool

func NewDirProvider added in v0.8.0

func NewDirProvider(ctx *config.ProjectContext, includePastResources bool) schema.Provider

func NewPlanProvider added in v0.8.0

func NewPlanProvider(ctx *config.ProjectContext, includePastResources bool) schema.Provider

func NewStateJSONProvider added in v0.8.0

func NewStateJSONProvider(ctx *config.ProjectContext, includePastResources bool) schema.Provider

func NewTerragruntHCLProvider added in v0.9.23

func NewTerragruntHCLProvider(rootPath hcl.RootPath, ctx *config.ProjectContext) schema.Provider

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

func NewTerragruntProvider added in v0.9.7

func NewTerragruntProvider(ctx *config.ProjectContext, includePastResources bool) schema.Provider

func ReadPlanCache added in v0.9.12

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

func StripSetupTerraformWrapper added in v0.9.14

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 added in v0.9.12

func UsePlanCache(p *DirProvider) bool

func WritePlanCache added in v0.9.12

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

Types

type CmdError added in v0.6.3

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

func (*CmdError) Error added in v0.6.3

func (e *CmdError) Error() string

type CmdOptions added in v0.6.2

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

type ConfLoader added in v0.10.31

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

func NewConfLoader added in v0.10.31

func NewConfLoader(conf gjson.Result) *ConfLoader

func (*ConfLoader) GetModuleConfJSON added in v0.10.31

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

func (*ConfLoader) GetResourceConfJSON added in v0.10.31

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

type Configuration added in v0.9.19

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

type DirProvider added in v0.8.0

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 added in v0.9.0

func (p *DirProvider) AddMetadata(metadata *schema.ProjectMetadata)

func (*DirProvider) Context added in v0.10.34

func (p *DirProvider) Context() *config.ProjectContext

func (*DirProvider) DisplayType added in v0.8.0

func (p *DirProvider) DisplayType() string

func (*DirProvider) LoadResources added in v0.8.0

func (p *DirProvider) LoadResources(usage schema.UsageMap) ([]*schema.Project, error)

func (*DirProvider) Type added in v0.8.0

func (p *DirProvider) Type() string

type HCLProject added in v0.10.14

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

type HCLProvider added in v0.9.19

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

func NewHCLProvider added in v0.9.19

func NewHCLProvider(ctx *config.ProjectContext, rootPath hcl.RootPath, config *HCLProviderConfig, opts ...hcl.Option) (*HCLProvider, error)

NewHCLProvider returns a HCLProvider with a hcl.Parser initialised using the config.ProjectContext. 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 (*HCLProvider) AddMetadata added in v0.9.19

func (p *HCLProvider) AddMetadata(metadata *schema.ProjectMetadata)

func (*HCLProvider) Context added in v0.10.34

func (p *HCLProvider) Context() *config.ProjectContext

func (*HCLProvider) DisplayType added in v0.9.19

func (p *HCLProvider) DisplayType() string

func (*HCLProvider) EnvName added in v0.10.35

func (p *HCLProvider) EnvName() string

func (*HCLProvider) InvalidateCache added in v0.10.0

func (p *HCLProvider) InvalidateCache() *HCLProvider

InvalidateCache removes the module cache from the prior hcl parse.

func (*HCLProvider) LoadPlanJSON added in v0.9.22

func (p *HCLProvider) LoadPlanJSON() HCLProject

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

func (*HCLProvider) LoadResources added in v0.9.19

func (p *HCLProvider) LoadResources(usage schema.UsageMap) ([]*schema.Project, 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 Infracost resources.

func (*HCLProvider) Module added in v0.10.33

func (p *HCLProvider) 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 (*HCLProvider) ProjectName added in v0.10.33

func (p *HCLProvider) ProjectName() string

func (*HCLProvider) RelativePath added in v0.10.33

func (p *HCLProvider) RelativePath() string

func (*HCLProvider) TerraformVarFiles added in v0.10.33

func (p *HCLProvider) TerraformVarFiles() []string

func (*HCLProvider) Type added in v0.9.19

func (p *HCLProvider) Type() string

func (*HCLProvider) YAML added in v0.10.33

func (p *HCLProvider) YAML() string

type HCLProviderConfig added in v0.10.0

type HCLProviderConfig struct {
	SuppressLogging     bool
	CacheParsingModules bool
	SkipAutoDetection   bool
}

type MalformedRegistryURLErr added in v0.9.23

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 added in v0.9.23

func (err MalformedRegistryURLErr) Error() string

type ModuleCall added in v0.9.19

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

type ModuleConfig added in v0.9.22

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

type ModuleDownloadErr added in v0.9.23

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

ModuleDownloadErr is returned if Terragrunt failed to download the module.

func (ModuleDownloadErr) Error added in v0.9.23

func (err ModuleDownloadErr) Error() string

type ModuleOut added in v0.9.22

type ModuleOut struct {
	PlanModule   PlanModule
	ModuleConfig ModuleConfig
}

type ParsedPlanConfiguration added in v0.10.31

type ParsedPlanConfiguration struct {
	PastResources        []*schema.PartialResource
	PastResourceDatas    []*schema.ResourceData
	CurrentResources     []*schema.PartialResource
	CurrentResourceDatas []*schema.ResourceData
	ProviderMetadata     []schema.ProviderMetadata
	RemoteModuleCalls    []string
}

type Parser added in v0.7.17

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

func NewParser added in v0.7.17

func NewParser(ctx *config.ProjectContext, includePastResources bool) *Parser

type PlanJSONProvider added in v0.8.0

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

func NewPlanJSONProvider added in v0.8.0

func NewPlanJSONProvider(ctx *config.ProjectContext, includePastResources bool) *PlanJSONProvider

func (*PlanJSONProvider) AddMetadata added in v0.9.0

func (p *PlanJSONProvider) AddMetadata(metadata *schema.ProjectMetadata)

func (*PlanJSONProvider) Context added in v0.10.34

func (p *PlanJSONProvider) Context() *config.ProjectContext

func (*PlanJSONProvider) DisplayType added in v0.8.0

func (p *PlanJSONProvider) DisplayType() string

func (*PlanJSONProvider) LoadResources added in v0.8.0

func (p *PlanJSONProvider) LoadResources(usage schema.UsageMap) ([]*schema.Project, error)

func (*PlanJSONProvider) LoadResourcesFromSrc added in v0.9.19

func (p *PlanJSONProvider) LoadResourcesFromSrc(usage schema.UsageMap, j []byte, spinner *ui.Spinner) (*schema.Project, error)

func (*PlanJSONProvider) Type added in v0.8.0

func (p *PlanJSONProvider) Type() string

type PlanModule added in v0.9.22

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

type PlanProvider added in v0.8.0

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

func (*PlanProvider) DisplayType added in v0.8.0

func (p *PlanProvider) DisplayType() string

func (*PlanProvider) LoadResources added in v0.8.0

func (p *PlanProvider) LoadResources(usage schema.UsageMap) ([]*schema.Project, error)

func (*PlanProvider) Type added in v0.8.0

func (p *PlanProvider) Type() string

type PlanSchema added in v0.9.19

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"`

	// InfracostResourceChanges 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 `infracost_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.
	InfracostResourceChanges []ResourceChangesJSON `json:"infracost_resource_changes"`
}

type PlanValues added in v0.10.17

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

type ProviderConfig added in v0.9.19

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

type RegistryAPIErr added in v0.9.23

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 added in v0.9.23

func (err RegistryAPIErr) Error() string

type ResourceChange added in v0.9.19

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

type ResourceChangesJSON added in v0.9.19

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 added in v0.9.19

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 added in v0.9.19

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"`
	InfracostMetadata map[string]interface{} `json:"infracost_metadata"`
}

type ResourceOutput added in v0.9.22

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

type ResourceRegistryMap added in v0.6.3

type ResourceRegistryMap map[string]*schema.RegistryItem

func GetResourceRegistryMap added in v0.6.0

func GetResourceRegistryMap() *ResourceRegistryMap

func (*ResourceRegistryMap) GetCustomRefIDFunc added in v0.9.19

func (r *ResourceRegistryMap) GetCustomRefIDFunc(resourceDataType string) schema.ReferenceIDFunc

func (*ResourceRegistryMap) GetDefaultRefIDFunc added in v0.10.0

func (r *ResourceRegistryMap) GetDefaultRefIDFunc(resourceDataType string) schema.ReferenceIDFunc

func (*ResourceRegistryMap) GetReferenceAttributes added in v0.9.19

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

type RunShowOptions added in v0.9.7

type RunShowOptions struct {
	CmdOptions *CmdOptions
}

type ServiceDiscoveryErr added in v0.9.23

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 added in v0.9.23

func (err ServiceDiscoveryErr) Error() string

type StateJSONProvider added in v0.8.0

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

func (*StateJSONProvider) AddMetadata added in v0.9.0

func (p *StateJSONProvider) AddMetadata(metadata *schema.ProjectMetadata)

func (*StateJSONProvider) Context added in v0.10.34

func (p *StateJSONProvider) Context() *config.ProjectContext

func (*StateJSONProvider) DisplayType added in v0.8.0

func (p *StateJSONProvider) DisplayType() string

func (*StateJSONProvider) LoadResources added in v0.8.0

func (p *StateJSONProvider) LoadResources(usage schema.UsageMap) ([]*schema.Project, error)

func (*StateJSONProvider) Type added in v0.8.0

func (p *StateJSONProvider) Type() string

type TerraformRegistryGetter added in v0.9.23

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

TerraformRegistryGetter is a Getter (from go-getter) 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. GH issue: https://github.com/gruntwork-io/terragrunt/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. GH issue: https://github.com/gruntwork-io/terragrunt/issues/1772

func (*TerraformRegistryGetter) ClientMode added in v0.9.23

func (tfrGetter *TerraformRegistryGetter) ClientMode(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) Context added in v0.9.23

func (tfrGetter *TerraformRegistryGetter) Context() context.Context

Context returns the go context to use for the underlying fetch routines. This depends on what client is set.

func (*TerraformRegistryGetter) Get added in v0.9.23

func (tfrGetter *TerraformRegistryGetter) Get(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 added in v0.9.23

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 added in v0.9.23

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 added in v0.9.23

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

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

type TerragruntHCLProvider added in v0.9.23

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

func (*TerragruntHCLProvider) AddMetadata added in v0.9.23

func (p *TerragruntHCLProvider) AddMetadata(metadata *schema.ProjectMetadata)

func (*TerragruntHCLProvider) Context added in v0.10.34

func (*TerragruntHCLProvider) DisplayType added in v0.9.23

func (p *TerragruntHCLProvider) DisplayType() string

func (*TerragruntHCLProvider) EnvName added in v0.10.35

func (p *TerragruntHCLProvider) EnvName() string

func (*TerragruntHCLProvider) LoadResources added in v0.9.23

func (p *TerragruntHCLProvider) LoadResources(usage schema.UsageMap) ([]*schema.Project, error)

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

func (*TerragruntHCLProvider) ProjectName added in v0.10.33

func (p *TerragruntHCLProvider) ProjectName() string

func (*TerragruntHCLProvider) RelativePath added in v0.10.33

func (p *TerragruntHCLProvider) RelativePath() string

func (*TerragruntHCLProvider) TerraformVarFiles added in v0.10.33

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

func (*TerragruntHCLProvider) Type added in v0.9.23

func (p *TerragruntHCLProvider) Type() string

func (*TerragruntHCLProvider) YAML added in v0.10.33

func (p *TerragruntHCLProvider) YAML() string

type TerragruntInfo added in v0.9.7

type TerragruntInfo struct {
	ConfigPath string
	WorkingDir string
}

type TerragruntOutputCache added in v0.10.33

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

func (*TerragruntOutputCache) Set added in v0.10.33

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 added in v0.9.7

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

func (*TerragruntProvider) AddMetadata added in v0.9.7

func (p *TerragruntProvider) AddMetadata(metadata *schema.ProjectMetadata)

func (*TerragruntProvider) Context added in v0.10.34

func (*TerragruntProvider) DisplayType added in v0.9.7

func (p *TerragruntProvider) DisplayType() string

func (*TerragruntProvider) LoadResources added in v0.9.7

func (p *TerragruntProvider) LoadResources(usage schema.UsageMap) ([]*schema.Project, error)

func (*TerragruntProvider) Type added in v0.9.7

func (p *TerragruntProvider) Type() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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