modules

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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() *Cache

NewCacheFromManifest creates a new cache from a module manifest

type LoaderOption added in v0.9.22

type LoaderOption func(l *ModuleLoader)

LoaderOption defines a function that can set properties on an ModuleLoader.

func LoaderWithSpinner added in v0.9.22

func LoaderWithSpinner(f ui.SpinnerFunc) LoaderOption

LoaderWithSpinner enables the ModuleLoader to use an ui.Spinner to show the progress of loading the modules.

type Manifest

type Manifest struct {
	Modules []*ManifestModule `json:"Modules"`
}

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

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 {
	Path string
	// 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(path string, opts ...LoaderOption) *ModuleLoader

NewModuleLoader constructs a new module loader

func (*ModuleLoader) Load

func (m *ModuleLoader) Load() (*Manifest, 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() *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) *RegistryLoader

NewRegistryLoader constructs a registry loader

type RegistryLookupResult

type RegistryLookupResult struct {
	Source      string
	Version     string
	DownloadURL string
}

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

Jump to

Keyboard shortcuts

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