terraform

package
v0.0.0-...-55ed90b Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: Apache-2.0 Imports: 64 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmd

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

func CreateConfigFile

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

func IsTerraformDir

func IsTerraformDir(path string) bool

func NewDirProvider

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

func NewPlanProvider

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

func NewStateJSONProvider

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

func NewTerragruntProvider

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

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 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 *schema.ProjectMetadata)

func (*DirProvider) DisplayType

func (p *DirProvider) DisplayType() string

func (*DirProvider) LoadResources

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

func (*DirProvider) Type

func (p *DirProvider) Type() string

type HCLProject

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

type HCLProvider

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

func NewHCLProvider

func NewHCLProvider(ctx *config.ProjectContext, 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

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

func (*HCLProvider) DisplayType

func (p *HCLProvider) DisplayType() string

func (*HCLProvider) InvalidateCache

func (p *HCLProvider) InvalidateCache() *HCLProvider

InvalidateCache removes the module cache from the prior hcl parse.

func (*HCLProvider) LoadPlanJSONs

func (p *HCLProvider) LoadPlanJSONs() []HCLProject

LoadPlanJSONs parses the found directories and return the blocks in Terraform plan JSON format.

func (*HCLProvider) LoadResources

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) Modules

func (p *HCLProvider) Modules() []HCLProject

Modules parses the found directories into hcl modules representing a config tree of Terraform information. Modules 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) Type

func (p *HCLProvider) Type() string

type HCLProviderConfig

type HCLProviderConfig struct {
	SuppressLogging     bool
	CacheParsingModules 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"`
}

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 Parser

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

func NewParser

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

type PlanJSONProvider

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

func NewPlanJSONProvider

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

func (*PlanJSONProvider) AddMetadata

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

func (*PlanJSONProvider) DisplayType

func (p *PlanJSONProvider) DisplayType() string

func (*PlanJSONProvider) LoadResources

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

func (*PlanJSONProvider) LoadResourcesFromSrc

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

func (*PlanJSONProvider) Type

func (p *PlanJSONProvider) Type() 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 schema.UsageMap) ([]*schema.Project, error)

func (*PlanProvider) Type

func (p *PlanProvider) Type() 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"`

	// 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

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

type ProviderConfig

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

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

type ResourceOutput

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

type ResourceRegistryMap

type ResourceRegistryMap map[string]*schema.RegistryItem

func GetResourceRegistryMap

func GetResourceRegistryMap() *ResourceRegistryMap

func (*ResourceRegistryMap) GetCustomRefIDFunc

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

func (*ResourceRegistryMap) GetDefaultRefIDFunc

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

func (*ResourceRegistryMap) GetReferenceAttributes

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

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 *schema.ProjectMetadata)

func (*StateJSONProvider) DisplayType

func (p *StateJSONProvider) DisplayType() string

func (*StateJSONProvider) LoadResources

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

func (*StateJSONProvider) Type

func (p *StateJSONProvider) Type() string

type TerraformRegistryGetter

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

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

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

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

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 string
	// contains filtered or unexported fields
}

func NewTerragruntHCLProvider

func NewTerragruntHCLProvider(ctx *config.ProjectContext, includePastResources bool) *TerragruntHCLProvider

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

func (*TerragruntHCLProvider) AddMetadata

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

func (*TerragruntHCLProvider) DisplayType

func (p *TerragruntHCLProvider) DisplayType() string

func (*TerragruntHCLProvider) LoadResources

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) PrepWorkingDirs

func (p *TerragruntHCLProvider) PrepWorkingDirs() ([]*terragruntWorkingDirInfo, error)

func (*TerragruntHCLProvider) Type

func (p *TerragruntHCLProvider) Type() string

type TerragruntInfo

type TerragruntInfo struct {
	ConfigPath string
	WorkingDir string
}

type TerragruntProvider

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

func (*TerragruntProvider) AddMetadata

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

func (*TerragruntProvider) DisplayType

func (p *TerragruntProvider) DisplayType() string

func (*TerragruntProvider) LoadResources

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

func (*TerragruntProvider) Type

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