modules

package
v0.10.39 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGitSSHSource added in v0.10.32

func IsGitSSHSource(u *url.URL) bool

IsGitSSHSource returns if the url u is a valid git ssh source. Param u is expected to be an url that has been transformed by a go-getter Detect pass, removing shorthand and aliased for various sources.

func IsLocalModule added in v0.10.37

func IsLocalModule(source string) bool

IsLocalModule checks if the module is a local module by checking if the module source starts with any known local prefixes

func TransformSSHToHttps added in v0.10.32

func TransformSSHToHttps(u *url.URL) (*url.URL, error)

TransformSSHToHttps transforms a Terraform module source url to an HTTPS equivalent. This only handles source urls prefixed with ssh:: or git::ssh. The shorthand ssh source referenced here: https://developer.hashicorp.com/terraform/language/modules/sources#github e.g. "git@github.com:hashicorp/example.git" in not handled by this method as we expect the source to already be Detected to the valid longhand equivalent before calling this function. This can be achieved by calling getter.Detect(src) before calling TransformSSHToHttps.

Types

type BaseCredentialSet added in v0.10.7

type BaseCredentialSet struct {
	Token string
	Host  string
}

BaseCredentialSet are the underlying credentials that CredentialsSource will use if no other credentials can be found for a given host.

type Cache

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

Cache is a cache of modules that can be used to lookup modules to check if they've already been loaded.

This only works with modules that have the same identifier. It doesn't cache modules that are used multiple times with different identifiers. That is done separately by the PackageFetcher and only caches per-run of Infracost, so if you add the same module to your Terraform code it will redownload that module. We could optimize it by moving the package fetching cache logic into here, but it would be inconsistent with how terraform init works.

func NewCache

func NewCache(disco *Disco, logger zerolog.Logger) *Cache

NewCache creates a new cache from a module manifest

type CredentialsSource added in v0.10.7

type CredentialsSource struct {
	BaseCredentialSet BaseCredentialSet
	FetchToken        FetchTokenFunc
}

CredentialsSource is an object that may be able to provide credentials for a given module source.

func NewTerraformCredentialsSource added in v0.10.7

func NewTerraformCredentialsSource(creds BaseCredentialSet) (*CredentialsSource, error)

NewTerraformCredentialsSource returns a CredentialsSource attempting to set the BaseCredentialSet as the base. If creds doesn't contain static details, NewTerraformCredentialsSource will attempt to fill the credential set from the environment, returning an error if it cannot.

func (*CredentialsSource) ForHost added in v0.10.7

ForHost returns a non-nil HostCredentials if the source has credentials available for the host, and a nil HostCredentials if it does not.

func (*CredentialsSource) ForgetForHost added in v0.10.7

func (s *CredentialsSource) ForgetForHost(host svchost.Hostname) error

ForgetForHost is unimplemented but is required for the auth.CredentialsSource interface.

func (*CredentialsSource) StoreForHost added in v0.10.7

func (s *CredentialsSource) StoreForHost(host svchost.Hostname, credentials auth.HostCredentialsWritable) error

StoreForHost is unimplemented but is required for the auth.CredentialsSource interface.

type CustomGitGetter added in v0.10.32

type CustomGitGetter struct {
	*getter.GitGetter
}

CustomGitGetter extends the standard GitGetter transforming SSH sources to HTTPs first before attempting a Get. This means that we can attempt to use any Git credentials on the host machine to resolve the Get before falling back to SSH.

func (*CustomGitGetter) Get added in v0.10.32

func (g *CustomGitGetter) Get(dst string, u *url.URL) error

Get overrides the standard Get method transforming SSH urls to their HTTPS equivalent. Get then tries to get the new url into the dst, falling back to the original SSH url if an HTTPS get fails.

type Disco added in v0.10.7

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

Disco allows discovery on given hostnames. It tries to resolve a module source based on a set of discovery rules. It caches the results by hostname to avoid repeated requests for the same information. Therefore, it is advisable to use Disco per project and pass it to all required clients.

func NewDisco added in v0.10.7

func NewDisco(credentialsSource auth.CredentialsSource, logger zerolog.Logger) *Disco

NewDisco returns a Disco with the provided credentialsSource initialising the underlying Terraform Disco. If Credentials are nil then all registry requests will be unauthed.

func (*Disco) DownloadLocation added in v0.10.7

func (d *Disco) DownloadLocation(moduleURL RegistryURL, version string) (string, error)

func (*Disco) ModuleLocation added in v0.10.7

func (d *Disco) ModuleLocation(source string) (RegistryURL, bool, error)

ModuleLocation performs a discovery lookup for the given source and returns a RegistryURL with the real url of the module source and any required Credential information. It returns false if the module location is not recognised as a registry module.

type FetchTokenFunc added in v0.10.7

type FetchTokenFunc func(key string) string

FetchTokenFunc defines a function that returns a token for a given key. This can be an environment key, a header key, whatever the CredentialsSource requires.

type HostCredentials added in v0.10.7

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

func (HostCredentials) PrepareRequest added in v0.10.7

func (c HostCredentials) PrepareRequest(req *http.Request)

func (HostCredentials) Token added in v0.10.7

func (c HostCredentials) Token() string

type Manifest

type Manifest struct {
	Path    string            `json:"Path"`
	Version string            `json:"Version"`
	Modules []*ManifestModule `json:"Modules"`
	// contains filtered or unexported fields
}

Manifest is a struct that represents the JSON found in the manifest.json file in the .infracost dir It is used for caching the modules that have already been downloaded. It uses the same format as the .terraform/modules/modules.json file

func (Manifest) Get added in v0.10.31

func (m Manifest) Get(key string) ManifestModule

type ManifestModule

type ManifestModule struct {
	Key         string `json:"Key"`
	Source      string `json:"Source"`
	Version     string `json:"Version,omitempty"`
	Dir         string `json:"Dir"`
	DownloadURL string
}

ManifestModule represents a single module in the manifest.json file

func (ManifestModule) URL added in v0.10.31

func (m ManifestModule) URL() string

type ModuleLoader

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

ModuleLoader handles the loading of Terraform modules. It supports local, registry and other remote modules.

The path should be the root directory of the Terraform project. We use a distinct module loader per Terraform project, because at the moment the cache is per project. The cache reads the manifest.json file from the path's .infracost/terraform_modules directory. We could implement a global cache in the future, but for now have decided to go with the same approach as Terraform.

func NewModuleLoader

func NewModuleLoader(cachePath string, hclParser *SharedHCLParser, credentialsSource *CredentialsSource, sourceMap config.TerraformSourceMap, logger zerolog.Logger, moduleSync *intSync.KeyMutex) *ModuleLoader

NewModuleLoader constructs a new module loader

func (*ModuleLoader) Load

func (m *ModuleLoader) Load(path string) (man *Manifest, err error)

Load loads the modules from the given path. For each module it checks if the module has already been downloaded, by checking if iut exists in the manifest If not then it downloads the module from the registry or from a remote source and updates the module manifest with the latest metadata.

type PackageFetcher

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

PackageFetcher downloads modules from a remote source to the given destination This supports all the non-local and non-Terraform registry sources listed here: https://www.terraform.io/language/modules/sources

func NewPackageFetcher

func NewPackageFetcher(logger zerolog.Logger) *PackageFetcher

NewPackageFetcher constructs a new package fetcher

type RegistryLoader

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

RegistryLoader is a loader that can lookup modules from a Terraform Registry and download them to the given destination

func NewRegistryLoader

func NewRegistryLoader(packageFetcher *PackageFetcher, disco *Disco, logger zerolog.Logger) *RegistryLoader

NewRegistryLoader constructs a registry loader

func (*RegistryLoader) DownloadLocation added in v0.10.31

func (r *RegistryLoader) DownloadLocation(moduleURL RegistryURL, version string) (string, error)

type RegistryLookupResult

type RegistryLookupResult struct {
	OK        bool
	ModuleURL RegistryURL
	Version   string
}

RegistryLookupResult is returned when looking up the module to check if it exists in the registry and has a matching version

type RegistryURL added in v0.10.7

type RegistryURL struct {
	RawSource   string
	Host        string
	Location    string
	Credentials auth.HostCredentials
}

RegistryURL contains given URL information for a module source. This can be used to build http requests to download the module or check versions of the module.

type SharedHCLParser added in v0.10.31

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

func NewSharedHCLParser added in v0.10.31

func NewSharedHCLParser() *SharedHCLParser

func (*SharedHCLParser) ParseHCLFile added in v0.10.31

func (p *SharedHCLParser) ParseHCLFile(filename string) (*hcl.File, hcl.Diagnostics)

func (*SharedHCLParser) ParseJSONFile added in v0.10.31

func (p *SharedHCLParser) ParseJSONFile(filename string) (*hcl.File, hcl.Diagnostics)

type SourceMapResult added in v0.10.30

type SourceMapResult struct {
	Source   string
	Version  string
	RawQuery string
}

Jump to

Keyboard shortcuts

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