modules

package
v0.10.40 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: Apache-2.0 Imports: 45 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 NormalizeGitURLToHTTPS added in v0.10.40

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

NormalizeGitURLToHTTPS normalizes a Git source url to an HTTPS equivalent. It supports SSH URLs, as well as HTTPS URLS with usernames. This allows us to convert Terraform module source urls to HTTPS URLs, so we can attempt to download over HTTPS first using the existing credentials we have. It can also be used for generating links to resources within the module. There is a special case for Azure DevOps SSH URLs to handle converting them to the equivalent HTTPS URL.

func RecursivelyAddDirsToSparseCheckout added in v0.10.40

func RecursivelyAddDirsToSparseCheckout(repoRoot string, sourceURL string, packageFetcher *PackageFetcher, existingDirs []string, dirs []string, mu *sync.Mutex, logger zerolog.Logger, depth int) error

RecursivelyAddDirsToSparseCheckout adds the given directories to the sparse-checkout file list. It then checks any symlinks within the directories and adds them to the sparse-checkout file list as well.

func ResetGlobalModuleCache added in v0.10.40

func ResetGlobalModuleCache()

func ResolveSymLinkedDirs added in v0.10.40

func ResolveSymLinkedDirs(repoRoot, dir string) ([]string, error)

ResolveSymLinkedDirs traverses the directory to find symlinks and resolve their destinations

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 and normalizes SSH and HTTPS URLs so it can attempt to use the Git credentials on the host machine to resolve the Get before falling back to the original method. SSH URLs are transformed to their HTTPS equivalent before attempting a Get. HTTPS URLS are stripped of any credentials.

func (*CustomGitGetter) Get added in v0.10.32

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

Get overrides the standard Get method to normalize SSH and HTTPS URLs before attempting a Get. If the normalized URL fails it falls back to the original URL.

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(opts ModuleLoaderOptions) *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 ModuleLoaderOptions added in v0.10.40

type ModuleLoaderOptions struct {
	CachePath         string
	HCLParser         *SharedHCLParser
	CredentialsSource *CredentialsSource
	SourceMap         config.TerraformSourceMap
	Logger            zerolog.Logger
	ModuleSync        *intSync.KeyMutex
	RemoteCache       RemoteCache
}

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(remoteCache RemoteCache, logger zerolog.Logger, opts ...PackageFetcherOpts) *PackageFetcher

NewPackageFetcher constructs a new package fetcher

func (*PackageFetcher) Fetch added in v0.10.40

func (p *PackageFetcher) Fetch(moduleAddr string, dest string) error

fetch downloads the remote module using the go-getter library See: https://github.com/hashicorp/go-getter

type PackageFetcherOpts added in v0.10.40

type PackageFetcherOpts func(*PackageFetcher)

func WithGetters added in v0.10.40

func WithGetters(getters map[string]getter.Getter) PackageFetcherOpts

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

type RemoteCache interface {
	Exists(key string) (bool, error)
	Get(key string, dest string) error
	Put(key string, src string, ttl time.Duration) error
}

RemoteCache is an interface that defines the methods for a remote cache, i.e. an S3 bucket.

type S3Cache added in v0.10.40

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

func NewS3Cache added in v0.10.40

func NewS3Cache(region, bucketName, prefix string) (*S3Cache, error)

NewS3Cache creates a new S3Cache instance

func (*S3Cache) Exists added in v0.10.40

func (cache *S3Cache) Exists(key string) (bool, error)

Exists checks if the key exists in the S3 bucket

func (*S3Cache) Get added in v0.10.40

func (cache *S3Cache) Get(key, destPath string) error

Get downloads the key from the S3 bucket to the destPath

func (*S3Cache) Put added in v0.10.40

func (cache *S3Cache) Put(key, srcPath string, ttl time.Duration) error

Put uploads the srcPath to the S3 bucket with the key

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