Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseCredentialSet ¶
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.
type CredentialsSource ¶
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 ¶
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 ¶
func (s *CredentialsSource) ForHost(host svchost.Hostname) (auth.HostCredentials, error)
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 ¶
func (s *CredentialsSource) ForgetForHost(host svchost.Hostname) error
ForgetForHost is unimplemented but is required for the auth.CredentialsSource interface.
func (*CredentialsSource) StoreForHost ¶
func (s *CredentialsSource) StoreForHost(host svchost.Hostname, credentials auth.HostCredentialsWritable) error
StoreForHost is unimplemented but is required for the auth.CredentialsSource interface.
type Disco ¶
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 ¶
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 ¶
func (d *Disco) DownloadLocation(moduleURL RegistryURL, version string) (string, error)
func (*Disco) ModuleLocation ¶
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 ¶
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 ¶
type HostCredentials struct {
// contains filtered or unexported fields
}
func (HostCredentials) PrepareRequest ¶
func (c HostCredentials) PrepareRequest(req *http.Request)
func (HostCredentials) Token ¶
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) FindModulePath ¶
type ManifestModule ¶
type ManifestModule struct { Key string `json:"Key"` Source string `json:"Source"` Version string `json:"Version,omitempty"` Dir string `json:"Dir"` }
ManifestModule represents a single module in the manifest.json file
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, 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
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 ¶
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.